forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDomainsPage.js
More file actions
75 lines (69 loc) · 1.85 KB
/
DomainsPage.js
File metadata and controls
75 lines (69 loc) · 1.85 KB
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
66
67
68
69
70
71
72
73
74
75
import React from 'react'
import { number } from 'prop-types'
import { Trans } from '@lingui/macro'
import { Layout } from './Layout'
import { ListOf } from './ListOf'
import { Stack, Button, Heading, Box } from '@chakra-ui/core'
import {
REVERSE_PAGINATED_DOMAINS as BACKWARD,
PAGINATED_DOMAINS as FORWARD,
} from './graphql/queries'
import { useUserState } from './UserState'
import { Domain } from './Domain'
import { usePaginatedCollection } from './usePaginatedCollection'
export default function DomainsPage({ domainsPerPage = 10 }) {
const { currentUser } = useUserState()
const {
loading,
error,
nodes,
next,
previous,
hasNextPage,
hasPreviousPage,
} = usePaginatedCollection({
fetchForward: FORWARD,
fetchBackward: BACKWARD,
fetchHeaders: { authorization: currentUser.jwt },
recordsPerPage: domainsPerPage,
})
if (error)
return (
<p>
<Trans>error {error.message}</Trans>
</p>
)
if (loading)
return (
<p>
<Trans>Loading...</Trans>
</p>
)
return (
<Layout>
<Heading as="h1" mb="4">
<Trans>Domains</Trans>
</Heading>
<ListOf elements={nodes} ifEmpty={() => <Trans>No Domains</Trans>} mb="4">
{({ id, url, slug, lastRan }, index) => (
<Box key={`${slug}:${id}:${index}`}>
<Domain key={url} url={url} lastRan={lastRan} />
</Box>
)}
</ListOf>
<Stack isInline align="center" mb="4">
<Button
onClick={previous}
disable={!!hasPreviousPage}
aria-label="Previous page"
>
<Trans>Previous</Trans>
</Button>
<Button onClick={next} disable={!!hasNextPage} aria-label="Next page">
<Trans>Next</Trans>
</Button>
</Stack>
</Layout>
)
}
DomainsPage.propTypes = { domainsPerPage: number }