1 |
917be067
|
Fantič
|
import React, { useEffect, useState } from "react"
|
2 |
|
|
import { log } from "../logging/logger"
|
3 |
|
|
import { DrawerScreenProps } from "@react-navigation/drawer"
|
4 |
|
|
import { RootDrawerParamList } from "../components/Navigation"
|
5 |
b225ffee
|
Fantič
|
import { Box, Button, ChevronDownIcon, ChevronUpIcon, CloseIcon, Flex, HStack, Icon, IconButton, MinusIcon, Popover, Pressable, ScrollView, Switch, Text, TextArea, VStack } from "native-base"
|
6 |
917be067
|
Fantič
|
import { SortOptions } from "../types/general"
|
7 |
b225ffee
|
Fantič
|
import { Note } from "../types/note"
|
8 |
|
|
import NotesListView from "../components/notes/NotesListView"
|
9 |
|
|
import { G, Path } from "react-native-svg"
|
10 |
|
|
import { MessageIcon } from "../components/general/Icons"
|
11 |
|
|
import { ConfirmDialog } from "../components/general/Dialogs"
|
12 |
917be067
|
Fantič
|
const NotesViewPage = ({ route, navigation }: DrawerScreenProps<RootDrawerParamList, 'Notes'>) => {
|
13 |
|
|
|
14 |
|
|
const [isSortOpen, setIsSortOpen] = useState(false);
|
15 |
|
|
|
16 |
|
|
const [myCommentsCheck, setMyCommentsCheck] = useState(false);
|
17 |
|
|
const [generalCommentsCheck, setGeneralCommentsCheck] = useState(true);
|
18 |
|
|
|
19 |
b225ffee
|
Fantič
|
const [replyingTo, setReplyingTo] = useState<{ messageId: string; userName: string } | null>(null);
|
20 |
|
|
|
21 |
|
|
const cancelRef = React.useRef(null)
|
22 |
|
|
|
23 |
|
|
const notes = [
|
24 |
|
|
{
|
25 |
|
|
uuid: "fadfsfdsaf",
|
26 |
|
|
username: "Alice",
|
27 |
|
|
userId: "123",
|
28 |
|
|
note: "Buy milk and bread",
|
29 |
|
|
avatarUrl: "martin.png",
|
30 |
|
|
items: [],
|
31 |
|
|
createdTime: new Date("2022-01-01T10:00:00Z"),
|
32 |
|
|
updatedTime: new Date("2022-01-01T12:00:00Z"),
|
33 |
|
|
noteColor: "#FFA500",
|
34 |
|
|
},
|
35 |
|
|
{
|
36 |
|
|
uuid: "fadfsfdsaf",
|
37 |
|
|
username: "Bob",
|
38 |
|
|
userId: "456",
|
39 |
|
|
note: "Call Jane at 2 PM, Call Jane at 2 PM, Call Jane at 2 PM, Call Jane at 2 PM, Call Jane at 2 PM, Call Jane at 2 PM, Call Jane at 2 PM, Call Jane at 2 PM ,Call Jane at 2 PM",
|
40 |
|
|
avatarUrl: "https://example.com/avatar2.jpg",
|
41 |
|
|
items: ["Jane"],
|
42 |
|
|
createdTime: new Date("2022-01-02T10:00:00Z"),
|
43 |
|
|
updatedTime: new Date("2022-01-02T14:00:00Z"),
|
44 |
|
|
noteColor: "#6495ED",
|
45 |
|
|
},
|
46 |
|
|
{
|
47 |
|
|
uuid: "fadfsfdsaf",
|
48 |
|
|
username: "Charlie",
|
49 |
|
|
userId: "789",
|
50 |
|
|
note: "Pick up dry cleaning",
|
51 |
|
|
avatarUrl: "https://example.com/avatar3.jpg",
|
52 |
|
|
items: ["dry cleaning"],
|
53 |
|
|
createdTime: new Date("2022-01-03T10:00:00Z"),
|
54 |
|
|
updatedTime: new Date("2022-01-03T12:30:00Z"),
|
55 |
|
|
noteColor: "#FFA07A",
|
56 |
|
|
},
|
57 |
|
|
{
|
58 |
|
|
uuid: "fadfsfdsaf",
|
59 |
|
|
username: "Dave",
|
60 |
|
|
userId: "012",
|
61 |
|
|
note: "Finish report by Friday",
|
62 |
|
|
avatarUrl: "https://example.com/avatar4.jpg",
|
63 |
|
|
items: ["report"],
|
64 |
|
|
createdTime: new Date("2022-01-04T10:00:00Z"),
|
65 |
|
|
updatedTime: new Date("2022-01-04T16:00:00Z"),
|
66 |
|
|
noteColor: "#7B68EE",
|
67 |
|
|
},
|
68 |
|
|
{
|
69 |
|
|
uuid: "fadfsfdsaf",
|
70 |
|
|
username: "Eve",
|
71 |
|
|
userId: "345",
|
72 |
|
|
note: "Buy flowers for mom's birthday",
|
73 |
|
|
avatarUrl: "https://example.com/avatar5.jpg",
|
74 |
|
|
items: ["flowers"],
|
75 |
|
|
createdTime: new Date("2022-01-05T10:00:00Z"),
|
76 |
|
|
updatedTime: new Date("2022-01-05T18:00:00Z"),
|
77 |
|
|
noteColor: "#F08080",
|
78 |
|
|
},
|
79 |
|
|
{
|
80 |
|
|
uuid: "fadfsfdsaf",
|
81 |
|
|
username: "Frank",
|
82 |
|
|
userId: "678",
|
83 |
|
|
note: "Schedule dentist appointment",
|
84 |
|
|
avatarUrl: "https://example.com/avatar6.jpg",
|
85 |
|
|
items: ["dentist appointment"],
|
86 |
|
|
createdTime: new Date("2022-01-06T10:00:00Z"),
|
87 |
|
|
updatedTime: new Date("2022-01-06T11:00:00Z"),
|
88 |
|
|
noteColor: "#98FB98",
|
89 |
|
|
},
|
90 |
|
|
{
|
91 |
|
|
uuid: "fadfsfdsaf",
|
92 |
|
|
username: "Grace",
|
93 |
|
|
userId: "901",
|
94 |
|
|
note: "Book hotel for vacation",
|
95 |
|
|
avatarUrl: "https://example.com/avatar7.jpg",
|
96 |
|
|
items: ["hotel"],
|
97 |
|
|
createdTime: new Date("2022-01-07T10:00:00Z"),
|
98 |
|
|
updatedTime: new Date("2022-01-07T15:00:00Z"),
|
99 |
|
|
noteColor: "#87CEFA",
|
100 |
|
|
},
|
101 |
|
|
{
|
102 |
|
|
uuid: "fadfsfdsaf",
|
103 |
|
|
username: "Alice",
|
104 |
|
|
userId: "123",
|
105 |
|
|
note: "Buy milk and bread",
|
106 |
|
|
avatarUrl: "https://example.com/avatar1.jpg",
|
107 |
|
|
items: ["milk", "bread"],
|
108 |
|
|
createdTime: new Date("2022-01-01T10:00:00Z"),
|
109 |
|
|
updatedTime: new Date("2022-01-01T12:00:00Z"),
|
110 |
|
|
noteColor: "#FFA500",
|
111 |
|
|
},
|
112 |
|
|
{
|
113 |
|
|
uuid: "fadfsfdsaf",
|
114 |
|
|
username: "Bob",
|
115 |
|
|
userId: "456",
|
116 |
|
|
note: "Call Jane at 2 PM, Call Jane at 2 PM, Call Jane at 2 PM, Call Jane at 2 PM, Call Jane at 2 PM, Call Jane at 2 PM, Call Jane at 2 PM, Call Jane at 2 PM ,Call Jane at 2 PM",
|
117 |
|
|
avatarUrl: "https://example.com/avatar2.jpg",
|
118 |
|
|
items: ["Jane"],
|
119 |
|
|
createdTime: new Date("2022-01-02T10:00:00Z"),
|
120 |
|
|
updatedTime: new Date("2022-01-02T14:00:00Z"),
|
121 |
|
|
noteColor: "#6495ED",
|
122 |
|
|
},
|
123 |
|
|
{
|
124 |
|
|
uuid: "fadfsfdsaf",
|
125 |
|
|
username: "Charlie",
|
126 |
|
|
userId: "789",
|
127 |
|
|
note: "Pick up dry cleaning",
|
128 |
|
|
avatarUrl: "https://example.com/avatar3.jpg",
|
129 |
|
|
items: ["dry cleaning"],
|
130 |
|
|
createdTime: new Date("2022-01-03T10:00:00Z"),
|
131 |
|
|
updatedTime: new Date("2022-01-03T12:30:00Z"),
|
132 |
|
|
noteColor: "#FFA07A",
|
133 |
|
|
},
|
134 |
|
|
{
|
135 |
|
|
uuid: "fadfsfdsaf",
|
136 |
|
|
username: "Dave",
|
137 |
|
|
userId: "012",
|
138 |
|
|
note: "Finish report by Friday",
|
139 |
|
|
avatarUrl: "https://example.com/avatar4.jpg",
|
140 |
|
|
items: ["report"],
|
141 |
|
|
createdTime: new Date("2022-01-04T10:00:00Z"),
|
142 |
|
|
updatedTime: new Date("2022-01-04T16:00:00Z"),
|
143 |
|
|
noteColor: "#7B68EE",
|
144 |
|
|
},
|
145 |
|
|
{
|
146 |
|
|
uuid: "fadfsfdsaf",
|
147 |
|
|
username: "Eve",
|
148 |
|
|
userId: "345",
|
149 |
|
|
note: "Buy flowers for mom's birthday",
|
150 |
|
|
avatarUrl: "https://example.com/avatar5.jpg",
|
151 |
|
|
items: ["flowers"],
|
152 |
|
|
createdTime: new Date("2022-01-05T10:00:00Z"),
|
153 |
|
|
updatedTime: new Date("2022-01-05T18:00:00Z"),
|
154 |
|
|
noteColor: "#F08080",
|
155 |
|
|
}];
|
156 |
|
|
|
157 |
|
|
const [confirmDialog, setConfirmDialog] = React.useState<{
|
158 |
|
|
headerText?: string;
|
159 |
|
|
bodyText?: string;
|
160 |
|
|
confirmText?: string;
|
161 |
|
|
confirmColor?: string;
|
162 |
|
|
cancelRef?: any;
|
163 |
|
|
onClose?: () => void;
|
164 |
|
|
onSubmit?: () => void;
|
165 |
|
|
} | null>(null);
|
166 |
917be067
|
Fantič
|
|
167 |
|
|
const [sortSettings, setSortSettings] = useState({
|
168 |
|
|
items: SortOptions.None,
|
169 |
|
|
date: SortOptions.None
|
170 |
|
|
});
|
171 |
|
|
|
172 |
|
|
const handleSortChanged = (key: "items" | "date") => {
|
173 |
|
|
let currentState = sortSettings[key];
|
174 |
|
|
if (currentState == SortOptions.None) {
|
175 |
|
|
setSortSettings({
|
176 |
|
|
...sortSettings,
|
177 |
|
|
[key]: SortOptions.Asc
|
178 |
|
|
})
|
179 |
|
|
}
|
180 |
|
|
else if (currentState == SortOptions.Asc) {
|
181 |
|
|
setSortSettings({
|
182 |
|
|
...sortSettings,
|
183 |
|
|
[key]: SortOptions.Desc
|
184 |
|
|
})
|
185 |
|
|
}
|
186 |
|
|
else {
|
187 |
|
|
setSortSettings({
|
188 |
|
|
...sortSettings,
|
189 |
|
|
[key]: SortOptions.None
|
190 |
|
|
})
|
191 |
|
|
}
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
const getSortIcon = (sortOption: SortOptions, size: string) => {
|
195 |
|
|
switch (sortOption) {
|
196 |
|
|
case SortOptions.Asc:
|
197 |
|
|
return <ChevronUpIcon size={size} />;
|
198 |
|
|
case SortOptions.Desc:
|
199 |
|
|
return <ChevronDownIcon size={size} />;
|
200 |
|
|
default:
|
201 |
|
|
return <MinusIcon size={size} />;
|
202 |
|
|
}
|
203 |
|
|
};
|
204 |
|
|
|
205 |
|
|
const getNotes = () => {
|
206 |
|
|
console.log("Get NOTES");
|
207 |
|
|
}
|
208 |
|
|
|
209 |
b225ffee
|
Fantič
|
const handleReply = (messageId: string, userName: string) => {
|
210 |
|
|
console.log("Handling reply: " + messageId);
|
211 |
|
|
setReplyingTo({ messageId, userName })
|
212 |
|
|
}
|
213 |
917be067
|
Fantič
|
|
214 |
b225ffee
|
Fantič
|
const handleEdit = (messageId: string, newMessage: string) => {
|
215 |
|
|
console.log("Handling edit:" + messageId + ", " + newMessage);
|
216 |
|
|
}
|
217 |
917be067
|
Fantič
|
|
218 |
b225ffee
|
Fantič
|
const handleDelete = (messageId: string) => {
|
219 |
|
|
console.log("Handling delete:" + messageId);
|
220 |
|
|
}
|
221 |
917be067
|
Fantič
|
|
222 |
b225ffee
|
Fantič
|
return (
|
223 |
|
|
<Box width="90%" marginLeft="5%">
|
224 |
|
|
<VStack>
|
225 |
|
|
<HStack marginTop="5%">
|
226 |
|
|
<Box width="30%" justifyContent={"center"}>
|
227 |
|
|
<Popover // @ts-ignore
|
228 |
|
|
trigger={triggerProps => {
|
229 |
|
|
return <Button colorScheme="primary" {...triggerProps} onPress={() => setIsSortOpen(true)}>
|
230 |
|
|
Sort Options
|
231 |
|
|
</Button>;
|
232 |
|
|
}} isOpen={isSortOpen} onClose={() => setIsSortOpen(!isSortOpen)}>
|
233 |
|
|
<Popover.Content w="48">
|
234 |
|
|
<Popover.Arrow />
|
235 |
|
|
<Popover.CloseButton onPress={() => setIsSortOpen(false)} />
|
236 |
|
|
<Popover.Header>Sort Options</Popover.Header>
|
237 |
|
|
<Popover.Body>
|
238 |
|
|
<VStack>
|
239 |
|
|
<Button size="md" variant="outline" onPress={() => handleSortChanged("items")}
|
240 |
|
|
rightIcon={getSortIcon(sortSettings.items, "sm")}
|
241 |
|
|
>
|
242 |
|
|
Items</Button>
|
243 |
|
|
<Button size="md" variant="outline" marginTop={"5%"} onPress={() => handleSortChanged("date")}
|
244 |
|
|
rightIcon={getSortIcon(sortSettings.date, "sm")}>
|
245 |
|
|
Date</Button>
|
246 |
|
|
</VStack>
|
247 |
|
|
</Popover.Body>
|
248 |
|
|
<Popover.Footer justifyContent="flex-end">
|
249 |
|
|
<Button.Group space={2}>
|
250 |
|
|
<Button colorScheme="coolGray" variant="ghost" onPress={() => setIsSortOpen(false)}>
|
251 |
|
|
Cancel
|
252 |
|
|
</Button>
|
253 |
|
|
<Button colorScheme="success" onPress={() => { setIsSortOpen(false); getNotes() }}>
|
254 |
|
|
Save
|
255 |
|
|
</Button>
|
256 |
|
|
</Button.Group>
|
257 |
|
|
</Popover.Footer>
|
258 |
|
|
</Popover.Content>
|
259 |
|
|
</Popover>
|
260 |
|
|
</Box>
|
261 |
|
|
<VStack width="70%" space="0">
|
262 |
|
|
<Flex direction="row" alignItems="center" justify="flex-end">
|
263 |
|
|
<Text>My comments</Text>
|
264 |
|
|
<Switch isChecked={myCommentsCheck} onValueChange={() => setMyCommentsCheck(!myCommentsCheck)} size="md" />
|
265 |
|
|
</Flex>
|
266 |
|
|
<Flex direction="row" alignItems="center" justify="flex-end" marginTop="-7.5%">
|
267 |
|
|
<Text>General comments</Text>
|
268 |
|
|
<Switch isChecked={generalCommentsCheck} onValueChange={() => setGeneralCommentsCheck(!generalCommentsCheck)} size="md" />
|
269 |
|
|
</Flex>
|
270 |
|
|
</VStack>
|
271 |
|
|
</HStack>
|
272 |
|
|
<Box h={replyingTo != null ? "62.5%" : "67.5%"}>
|
273 |
|
|
<NotesListView notes={notes} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} />
|
274 |
|
|
</Box>
|
275 |
|
|
{replyingTo != null &&
|
276 |
|
|
<Flex direction="row" alignItems="center" justify="flex-end" h="5%" marginRight="10%">
|
277 |
|
|
<Text>Replying to {replyingTo.userName}</Text>
|
278 |
|
|
<IconButton onPress={() => setReplyingTo(null)} size="sm" icon={<CloseIcon />} marginLeft="-1%">
|
279 |
|
|
</IconButton>
|
280 |
|
|
</Flex>
|
281 |
|
|
}
|
282 |
|
|
<HStack h={replyingTo != null ? "20%" : "15%"} marginTop={replyingTo != null ? "0%" : "5%"}>
|
283 |
|
|
<TextArea placeholder="Add comment" width="90%" autoCompleteType={undefined} ></TextArea>
|
284 |
|
|
<VStack>
|
285 |
|
|
<Box h={replyingTo != null ? "30%" : "45%"}></Box>
|
286 |
|
|
<Box marginLeft="2">
|
287 |
|
|
<Button startIcon={<MessageIcon color="#FFF" />}></Button>
|
288 |
|
|
</Box>
|
289 |
|
|
</VStack>
|
290 |
|
|
</HStack>
|
291 |
|
|
</VStack>
|
292 |
|
|
<ConfirmDialog {...confirmDialog} isShown={confirmDialog != null} cancelRef={cancelRef} />
|
293 |
|
|
</Box>
|
294 |
917be067
|
Fantič
|
);
|
295 |
|
|
}
|
296 |
|
|
|
297 |
|
|
export default NotesViewPage;
|