fix: correctly update displayed repos after fetch
All checks were successful
continuous-integration/drone/push Build is passing

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

View File

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