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>
|
<template>
|
||||||
<div v-if="error">
|
<div v-if="githubRepos && githubRepos.length > 0">
|
||||||
{{ error }}
|
<div v-for="repo in githubRepos">
|
||||||
</div>
|
|
||||||
<div v-else v-for="repo in githubRepos">
|
|
||||||
<p>{{ repo.name }} updated at {{ repo.updated_at }}</p>
|
<p>{{ repo.name }} updated at {{ repo.updated_at }}</p>
|
||||||
</div>
|
</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>
|
||||||
|
Loading…
Reference in New Issue
Block a user