| 68 | } |
| 69 | |
| 70 | function Post(props: { postId: number; setPostId: Setter<number> }) { |
| 71 | const state = useQuery(() => postsQueries.detail(props.postId)) |
| 72 | |
| 73 | return ( |
| 74 | <div> |
| 75 | <div> |
| 76 | <a onClick={() => props.setPostId(-1)} href="#"> |
| 77 | Back |
| 78 | </a> |
| 79 | </div> |
| 80 | <Switch> |
| 81 | <Match when={state.status === 'pending'}>Loading...</Match> |
| 82 | <Match when={state.status === 'error'}> |
| 83 | <span>Error: {(state.error as Error).message}</span> |
| 84 | </Match> |
| 85 | <Match when={state.data !== undefined}> |
| 86 | <> |
| 87 | <h1>{state.data?.title}</h1> |
| 88 | <div> |
| 89 | <p>{state.data?.body}</p> |
| 90 | </div> |
| 91 | <div>{state.isFetching ? 'Background Updating...' : ' '}</div> |
| 92 | </> |
| 93 | </Match> |
| 94 | </Switch> |
| 95 | </div> |
| 96 | ) |
| 97 | } |
| 98 | |
| 99 | const App: Component = () => { |
| 100 | const [postId, setPostId] = createSignal(-1) |