-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMissingPersons.tsx
More file actions
148 lines (133 loc) · 4.13 KB
/
MissingPersons.tsx
File metadata and controls
148 lines (133 loc) · 4.13 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import { NavLink, useSearchParams } from 'react-router-dom';
import { Flex, Grid } from 'src/shared/components/Layout';
import { Image } from 'src/shared/components/Media';
import { CardText, Text } from 'src/shared/components/Typography';
import { MissingPersonsArray } from 'src/shared/types';
import { normalizeName } from 'src/shared/utils';
interface MissingPersonsProps {
currentPage: number;
pageData: MissingPersonsArray;
pageSize: number;
}
export const MissingPersons = ({
currentPage,
pageData,
pageSize,
}: MissingPersonsProps) => {
const [searchParams, setSearchParams] = useSearchParams();
return (
<Grid css={{ gap: '1rem' }}>
<h2>Missing Persons</h2>
<section>
<Text as="h3"> Filters:</Text>
<Flex css={{ gap: '1rem' }}>
<Flex
as="label"
css={{ gap: '1ch', alignItems: 'center' }}
htmlFor="showOnlyMatching"
>
<input
type="checkbox"
name="showOnlyMatching"
id="showOnlyMatching"
checked={searchParams.get('showOnlyMatching') === 'true'}
onChange={() => {
setSearchParams((previous) => {
const previousEntries = Object.fromEntries(previous);
const showOnlyMatching =
previousEntries.showOnlyMatching === 'true';
return {
...previousEntries,
showOnlyMatching: String(!showOnlyMatching),
};
});
}}
/>
Show only matching
</Flex>
</Flex>
</section>
<Flex as="section" css={{ gap: '2rem', flexWrap: 'wrap' }}>
{pageData.map((missingPerson) => {
const {
CaseRef: caseRef,
Images: images,
Name: name,
PersonID: personID,
} = missingPerson;
// Split case number from case reference
const caseNumber = caseRef?.split(': ')[1];
// Normalize name
const normalizedName = normalizeName(name);
return (
<Grid
as={NavLink}
key={personID}
to={`/missing/${caseNumber}`}
css={{
border: '1px solid black',
padding: '1rem',
width: 'max-content',
height: 'max-content',
gap: '1rem',
textDecoration: 'none',
'&:hover': {
backgroundColor: '#F6F4F3',
},
}}
>
<Grid as="section" css={{ gap: '1rem' }}>
<span>
<CardText as="h3" css={{ color: 'black' }}>
{normalizedName}
</CardText>
</span>
<Image
src={images?.[0]}
alt={`A photo of ${normalizedName}`}
css={{ justifySelf: 'center' }}
/>
</Grid>
</Grid>
);
})}
</Flex>
<Flex css={{ gap: '1rem', justifyContent: 'center' }}>
{currentPage > 1 && (
<button
type="button"
onClick={() => {
setSearchParams((previous) => {
const previousEntries = Object.fromEntries(previous);
return {
...previousEntries,
page: String(currentPage - 1),
};
});
}}
>
Previous Page
</button>
)}
{pageData.length === pageSize && (
<button
type="button"
onClick={() => {
setSearchParams((previous) => {
const previousEntries = Object.fromEntries(previous);
return {
...previousEntries,
page: String(currentPage + 1),
};
});
}}
>
Next Page
</button>
)}
</Flex>
</Grid>
);
};