-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpage.tsx
65 lines (56 loc) · 1.54 KB
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use client'
import * as React from 'react'
import { graphql } from '@/fuse'
import { LaunchItem } from '@/components/LaunchItem'
import { LaunchDetails } from '@/components/LaunchDetails'
import styles from './page.module.css'
import { PageNumbers } from '@/components/PageNumbers'
import { useQuery } from '@/fuse/client'
import { useSearchParams } from 'next/navigation'
export default function Page() {
return (
<main className={styles.main}>
<h1>SpaceX Launches</h1>
<React.Suspense fallback={<p>Loading launches...</p>}>
<Launches />
</React.Suspense>
</main>
)
}
const LaunchesQuery = graphql(`
query Launches_SSR($offset: Int) {
launches(limit: 10, offset: $offset) {
nodes {
id
...LaunchFields
}
...TotalCountFields
}
}
`)
function Launches() {
const searchparams = useSearchParams()
const selected = searchparams!.get('selected')
const offset = searchparams!.has('offset')
? Number(searchparams!.get('offset'))
: 0
const [result] = useQuery({
query: LaunchesQuery,
variables: { offset },
})
return (
<>
<ul className={styles.list}>
{result.data?.launches.nodes.map(
(node) => node && <LaunchItem key={node.id} launch={node} />,
)}
</ul>
{result.data && (
<PageNumbers offset={offset} list={result.data.launches} limit={10} />
)}
<React.Suspense fallback={<p>Loading details...</p>}>
{selected && <LaunchDetails id={selected} />}
</React.Suspense>
</>
)
}