Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

Films.tsx

51 lines1.5 KB

1import { For, Match, Switch } from 'solid-js'
2import { A } from '@solidjs/router'
3import { useQuery } from '@tanstack/solid-query'
4import { filmsQueries } from './services/films/queries'
5​
6export default function Films() {
7 const query = useQuery(() => filmsQueries.list())
8​
9 return (
10 <Switch>
11 <Match when={query.status === 'pending'}>
12 <p>Loading...</p>
13 </Match>
14 <Match when={query.status === 'error'}>
15 <p>Error :(</p>
16 </Match>
17 <Match when={query.data}>
18 {(data) => (
19 <div>
20 <h2 class="text-4xl">Films</h2>
21 <For each={data().results}>
22 {(film) => {
23 const filmUrlParts = film.url.split('/').filter(Boolean)
24 const filmId = filmUrlParts[filmUrlParts.length - 1]
25 return (
26 <article>
27 <A
28 class="text-blue-500 hover:underline"
29 href={`/films/${filmId}`}
30 >
31 <h6 class="text-xl">
32 {film.episode_id}. {film.title}{' '}
33 <em>
34 (
35 {new Date(
36 Date.parse(film.release_date),
37 ).getFullYear()}
38 )
39 </em>
40 </h6>
41 </A>
42 </article>
43 )
44 }}
45 </For>
46 </div>
47 )}
48 </Match>
49 </Switch>
50 )