fix: correctly update displayed repos after fetch
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
28223c44d4
commit
aa82e265c8
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user