fix: correctly update displayed repos after fetch
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Lucien Cartier-Tilet 2023-05-05 00:38:37 +02:00
parent 28223c44d4
commit aa82e265c8
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
1 changed files with 13 additions and 11 deletions

View File

@ -1,13 +1,14 @@
<template>
<div v-if="error">
{{ error }}
</div>
<div v-else v-for="repo in githubRepos">
<p>{{ repo.name }} updated at {{ repo.updated_at }}</p>
<div v-if="githubRepos && githubRepos.length > 0">
<div v-for="repo in githubRepos">
<p>{{ repo.name }} updated at {{ repo.updated_at }}</p>
</div>
</div>
<p v-else>Erreur: {{ error }}</p>
</template>
<script setup lang="ts">
import { ref, Ref } from 'vue';
import { readFromCache } from '../composables/cache';
import {
GithubError,
@ -15,20 +16,21 @@ import {
getLatestRepositories,
} from '../composables/github';
let githubRepos: GithubRepo[] | null = null;
let error: GithubError | null;
let githubRepos: Ref<GithubRepo[]> = ref(null);
let error: Ref<GithubError> = ref(null);
const getRepositories = () => {
return getLatestRepositories('phundrak', 5);
};
readFromCache<GithubRepo[]>('latestRepos', getRepositories).subscribe({
next: (repos: GithubRepo[]) => {
githubRepos = repos;
error = null;
console.log('Received repos:', repos);
githubRepos.value = repos;
error.value = null;
},
error: (errorResponse: GithubError) => {
githubRepos = null;
error = errorResponse;
githubRepos.value = null;
error.value = errorResponse;
},
});
</script>