(props: { setPostId: Setter<number> })
| 19 | }) |
| 20 | |
| 21 | function Posts(props: { setPostId: Setter<number> }) { |
| 22 | const state = useQuery(() => postsQueries.list()) |
| 23 | |
| 24 | return ( |
| 25 | <div> |
| 26 | <h1>Posts</h1> |
| 27 | <div> |
| 28 | <Switch> |
| 29 | <Match when={state.status === 'pending'}>Loading...</Match> |
| 30 | <Match when={state.status === 'error'}> |
| 31 | <span>Error: {(state.error as Error).message}</span> |
| 32 | </Match> |
| 33 | <Match when={state.data !== undefined}> |
| 34 | <> |
| 35 | <div> |
| 36 | <For each={state.data}> |
| 37 | {(post) => ( |
| 38 | <p> |
| 39 | <a |
| 40 | onClick={() => props.setPostId(post.id)} |
| 41 | href="#" |
| 42 | style={ |
| 43 | // We can access the query data here to show bold links for |
| 44 | // ones that are cached |
| 45 | queryClient.getQueryData( |
| 46 | postsQueries.detail(post.id).queryKey, |
| 47 | ) |
| 48 | ? { |
| 49 | 'font-weight': 'bold', |
| 50 | color: 'green', |
| 51 | } |
| 52 | : {} |
| 53 | } |
| 54 | > |
| 55 | {post.title} |
| 56 | </a> |
| 57 | </p> |
| 58 | )} |
| 59 | </For> |
| 60 | </div> |
| 61 | <div>{state.isFetching ? 'Background Updating...' : ' '}</div> |
| 62 | </> |
| 63 | </Match> |
| 64 | </Switch> |
| 65 | </div> |
| 66 | </div> |
| 67 | ) |
| 68 | } |
| 69 | |
| 70 | function Post(props: { postId: number; setPostId: Setter<number> }) { |
| 71 | const state = useQuery(() => postsQueries.detail(props.postId)) |
nothing calls this directly
no test coverage detected