| 85 | } |
| 86 | |
| 87 | function Post(props: { postId: string; setPostId: Setter<string | null> }) { |
| 88 | const state = useQuery(() => postsQueries.detail(props.postId)) |
| 89 | |
| 90 | return ( |
| 91 | <div> |
| 92 | <div> |
| 93 | <a onClick={() => props.setPostId(null)} href="#"> |
| 94 | Back |
| 95 | </a> |
| 96 | </div> |
| 97 | <Switch> |
| 98 | <Match when={state.status === 'pending'}>Loading...</Match> |
| 99 | <Match when={state.status === 'error'}> |
| 100 | <span>Error: {(state.error as Error).message}</span> |
| 101 | </Match> |
| 102 | <Match when={state.data !== undefined}> |
| 103 | <> |
| 104 | <h1>{state.data?.title}</h1> |
| 105 | <div> |
| 106 | <p>{state.data?.body}</p> |
| 107 | </div> |
| 108 | <div>{state.isFetching ? 'Background Updating...' : ' '}</div> |
| 109 | </> |
| 110 | </Match> |
| 111 | </Switch> |
| 112 | </div> |
| 113 | ) |
| 114 | } |
| 115 | |
| 116 | const root = document.getElementById('root') |
| 117 | if (!root) throw new Error('Missing #root element') |