forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloatingMenu.js
More file actions
238 lines (221 loc) · 7.32 KB
/
FloatingMenu.js
File metadata and controls
238 lines (221 loc) · 7.32 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import { FloatingMenuLink } from './FloatingMenuLink'
import React from 'react'
import { Link as RouteLink } from 'react-router-dom'
import {
Stack,
Button,
Drawer,
DrawerBody,
DrawerFooter,
DrawerHeader,
DrawerOverlay,
DrawerContent,
useDisclosure,
Box,
Link,
Divider,
Image,
useToast,
Heading,
Icon,
} from '@chakra-ui/core'
import { TrackerButton } from './TrackerButton'
import { Trans, t } from '@lingui/macro'
import wordmark from './images/canada-wordmark.svg'
import reportIcon from './images/report-icon.svg'
import buildingIcon from './images/building-icon.svg'
import { useLingui } from '@lingui/react'
import { useUserState } from './UserState'
export const FloatingMenu = () => {
const { i18n } = useLingui()
const { _currentUser, isLoggedIn, logout } = useUserState()
const toast = useToast()
const {
isOpen: drawerIsOpen,
onOpen: drawerOnOpen,
onClose: drawerOnClose,
} = useDisclosure()
const drawerBtnRef = React.useRef()
return (
<Box
// position="fixed" as "sticky" doesn't play nice with firefox for android
position="fixed"
bottom={-1} // this gets rid of a small gap in firefox for android
zIndex={2}
height="min-content"
width="100%"
bg="white"
p="4px"
display={{ base: 'static', md: 'none' }}
>
<Stack isInline width="100%" rounded="md" spacing={0}>
<Link as={RouteLink} to="/organizations" flex="1 1 0">
<TrackerButton variant="primary" rounded={0} w="100%" h="100%">
<Image src={buildingIcon} size="16px" />
</TrackerButton>
</Link>
<Divider
orientation="vertical"
borderColor="accent"
borderWidth="2px"
ml={0}
/>
<Link as={RouteLink} to="/domains" flex="1 1 0">
<TrackerButton variant="primary" rounded={0} w="100%" h="100%">
<Icon name="https" height="16px" width="100%" />
</TrackerButton>
</Link>
<Divider
orientation="vertical"
borderColor="accent"
borderWidth="2px"
ml={0}
/>
<Link as={RouteLink} to="/dmarc-summaries" flex="1 1 0">
<TrackerButton variant="primary" rounded={0} w="100%" h="100%">
<Image src={reportIcon} size="16px" />
</TrackerButton>
</Link>
<Divider
orientation="vertical"
borderColor="accent"
borderWidth="2px"
ml={0}
/>
<Box flex="1 1 0">
<TrackerButton
ref={drawerBtnRef}
variant="primary"
onClick={drawerOnOpen}
rounded={0}
w="100%"
h="100%"
>
<Trans>Menu</Trans>
</TrackerButton>
</Box>
<Drawer
isOpen={drawerIsOpen}
placement="bottom"
onClose={drawerOnClose}
finalFocusRef={drawerBtnRef}
blockScrollOnMount={false} // blocking scroll causes bad behaviour in firefox for android
>
<DrawerOverlay />
<DrawerContent backgroundColor="primary" ml="auto" width="75%">
<Stack spacing="0px" mt="auto">
<DrawerHeader
mt="auto"
borderBottomWidth="1px"
borderBottomColor="accent"
mb="0px"
px="24px"
py="16px"
>
<Heading textAlign="right" color="white" size="xl" px="4px">
<Trans>Menu</Trans>
</Heading>
</DrawerHeader>
<DrawerBody px="24px" py="16px">
<Stack spacing="16px">
<FloatingMenuLink to="/" text={t`Home`} />
<FloatingMenuLink to="/user" text={t`Account Settings`} />
<FloatingMenuLink to="/admin" text={t`Admin Portal`} />
<Divider
borderWidth="2px"
borderColor="accent"
width="100%"
opacity="50%"
mt="0px"
/>
{isLoggedIn() ? (
<FloatingMenuLink
to="/"
text={t`Sign Out`}
onClick={() => {
logout()
toast({
title: t`Sign Out.`,
description: t`You have successfully been signed out.`,
status: 'success',
duration: 9000,
isClosable: true,
position: 'top-left',
})
}}
/>
) : (
<FloatingMenuLink to="/sign-in" text={t`Sign In`} />
)}
<Divider
borderWidth="2px"
borderColor="accent"
width="100%"
opacity="50%"
mt="0px"
/>
<FloatingMenuLink
to={
i18n.locale === 'en'
? 'https://www.canada.ca/en/transparency/privacy.html'
: 'https://www.canada.ca/fr/transparence/confidentialite.html'
}
text={t`Privacy`}
isExternal
/>
<FloatingMenuLink
to={
i18n.locale === 'en'
? 'https://www.canada.ca/en/transparency/terms.html'
: 'https://www.canada.ca/fr/transparence/avis.html'
}
text={t`Terms & conditions`}
isExternal
/>
<FloatingMenuLink
to={'https://github.com/canada-ca/tracker/issues'}
text={t`Report an Issue`}
isExternal
/>
</Stack>
</DrawerBody>
<DrawerFooter
borderTopWidth="1px"
borderTopColor="accent"
backgroundColor="gray.300"
>
<Stack isInline width="100%" justify="space-between">
<Image
src={wordmark}
width="147.2px"
alt={
i18n.locale === 'en'
? 'Symbol of the Government of Canada'
: 'Symbole du gouvernement du Canada'
}
color="white"
/>
<Button
color="primary"
bg="transparent"
borderColor="primary"
borderWidth="1px"
onClick={drawerOnClose}
>
<Trans>Close</Trans>
</Button>
</Stack>
</DrawerFooter>
</Stack>
</DrawerContent>
{
// Firefox for android makes the menu bar disappear when exiting the menu if the address bar is hidden initially,
// this brings the menu bar back
setTimeout(() => window.scrollBy(0, -1), 1)
}
</Drawer>
</Stack>
</Box>
)
}
FloatingMenu.propTypes = {}