Open History to see the last commit
1<script setup lang="ts">
2import { useQuery, useQueryClient } from '@tanstack/vue-query'
3import { postsQueries } from './services/posts/queries'
4β
5defineEmits<{ setPostId: [id: string] }>()
6β
7const queryClient = useQueryClient()
8β
9const { isPending, isError, isFetching, data, error } = useQuery(
10 postsQueries.list(),
11)
12</script>
13β
14<template>
15 <div>
16 <h1>Posts</h1>
17 <div>
18 <div v-if="isPending">Loading...</div>
19 <span v-else-if="isError">Error: {{ error?.message }}</span>
20 <template v-else-if="data">
21 <div>
22 <p v-for="post in data" :key="post.id">
23 <!-- We can find the existing query data here to show bold links for ones that are cached -->
24 <a
25 :href="`#${post.id}`"
26 :style="
27 queryClient.getQueryData(postsQueries.detail(post.id).queryKey)
28 ? { fontWeight: 'bold', color: 'green' }
29 : {}
30 "
31 @click.prevent="$emit('setPostId', post.id)"
32 >
33 {{ post.title }}
34 </a>
35 </p>
36 </div>
37 <div>{{ isFetching ? 'Background Updating...' : ' ' }}</div>
38 </template>
39 </div>
40 </div>
41</template>