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 |
bb690a9a
|
Fantič
|
import { useDispatch, useSelector } from "react-redux"
|
13 |
|
|
import { AppDispatch, RootState } from "../stores/store"
|
14 |
|
|
import LoadingBox from "../components/loading/LoadingBox"
|
15 |
|
|
import { getAllNotes } from "../stores/actions/notesThunks"
|
16 |
|
|
import { login } from "../stores/actions/userThunks"
|
17 |
917be067
|
Fantič
|
const NotesViewPage = ({ route, navigation }: DrawerScreenProps<RootDrawerParamList, 'Notes'>) => {
|
18 |
|
|
|
19 |
bb690a9a
|
Fantič
|
const { notes, notesLoading, requestPending } = useSelector((state: RootState) => state.noteViewState)
|
20 |
|
|
const dispatch = useDispatch<AppDispatch>();
|
21 |
|
|
|
22 |
917be067
|
Fantič
|
const [isSortOpen, setIsSortOpen] = useState(false);
|
23 |
|
|
|
24 |
|
|
const [myCommentsCheck, setMyCommentsCheck] = useState(false);
|
25 |
|
|
const [generalCommentsCheck, setGeneralCommentsCheck] = useState(true);
|
26 |
|
|
|
27 |
b225ffee
|
Fantič
|
const [replyingTo, setReplyingTo] = useState<{ messageId: string; userName: string } | null>(null);
|
28 |
|
|
|
29 |
bb690a9a
|
Fantič
|
const cancelRef = React.useRef(null);
|
30 |
b225ffee
|
Fantič
|
|
31 |
|
|
const [confirmDialog, setConfirmDialog] = React.useState<{
|
32 |
|
|
headerText?: string;
|
33 |
|
|
bodyText?: string;
|
34 |
|
|
confirmText?: string;
|
35 |
|
|
confirmColor?: string;
|
36 |
|
|
cancelRef?: any;
|
37 |
|
|
onClose?: () => void;
|
38 |
|
|
onSubmit?: () => void;
|
39 |
|
|
} | null>(null);
|
40 |
917be067
|
Fantič
|
|
41 |
|
|
const [sortSettings, setSortSettings] = useState({
|
42 |
|
|
items: SortOptions.None,
|
43 |
|
|
date: SortOptions.None
|
44 |
|
|
});
|
45 |
|
|
|
46 |
|
|
const handleSortChanged = (key: "items" | "date") => {
|
47 |
|
|
let currentState = sortSettings[key];
|
48 |
|
|
if (currentState == SortOptions.None) {
|
49 |
|
|
setSortSettings({
|
50 |
|
|
...sortSettings,
|
51 |
|
|
[key]: SortOptions.Asc
|
52 |
|
|
})
|
53 |
|
|
}
|
54 |
|
|
else if (currentState == SortOptions.Asc) {
|
55 |
|
|
setSortSettings({
|
56 |
|
|
...sortSettings,
|
57 |
|
|
[key]: SortOptions.Desc
|
58 |
|
|
})
|
59 |
|
|
}
|
60 |
|
|
else {
|
61 |
|
|
setSortSettings({
|
62 |
|
|
...sortSettings,
|
63 |
|
|
[key]: SortOptions.None
|
64 |
|
|
})
|
65 |
|
|
}
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
const getSortIcon = (sortOption: SortOptions, size: string) => {
|
69 |
|
|
switch (sortOption) {
|
70 |
|
|
case SortOptions.Asc:
|
71 |
|
|
return <ChevronUpIcon size={size} />;
|
72 |
|
|
case SortOptions.Desc:
|
73 |
|
|
return <ChevronDownIcon size={size} />;
|
74 |
|
|
default:
|
75 |
|
|
return <MinusIcon size={size} />;
|
76 |
|
|
}
|
77 |
|
|
};
|
78 |
|
|
|
79 |
bb690a9a
|
Fantič
|
// initial: load notes
|
80 |
|
|
useEffect(() => {
|
81 |
|
|
log.debug("NotesViewPage", "useEffect", "getNotes");
|
82 |
|
|
getNotes();
|
83 |
|
|
}, [])
|
84 |
|
|
|
85 |
|
|
// general comments check changed
|
86 |
|
|
useEffect(() => {
|
87 |
|
|
if(!notesLoading){
|
88 |
|
|
log.debug("NotesViewPage", "useEffect", "getNotes");
|
89 |
|
|
getNotes();
|
90 |
|
|
}
|
91 |
|
|
}, [generalCommentsCheck, myCommentsCheck])
|
92 |
|
|
|
93 |
|
|
|
94 |
917be067
|
Fantič
|
const getNotes = () => {
|
95 |
bb690a9a
|
Fantič
|
dispatch(getAllNotes({
|
96 |
|
|
myComments: myCommentsCheck,
|
97 |
|
|
generalComments: generalCommentsCheck,
|
98 |
|
|
sortOptions: sortSettings
|
99 |
|
|
}));
|
100 |
917be067
|
Fantič
|
}
|
101 |
|
|
|
102 |
b225ffee
|
Fantič
|
const handleReply = (messageId: string, userName: string) => {
|
103 |
|
|
console.log("Handling reply: " + messageId);
|
104 |
|
|
setReplyingTo({ messageId, userName })
|
105 |
|
|
}
|
106 |
917be067
|
Fantič
|
|
107 |
b225ffee
|
Fantič
|
const handleEdit = (messageId: string, newMessage: string) => {
|
108 |
|
|
console.log("Handling edit:" + messageId + ", " + newMessage);
|
109 |
|
|
}
|
110 |
917be067
|
Fantič
|
|
111 |
b225ffee
|
Fantič
|
const handleDelete = (messageId: string) => {
|
112 |
|
|
console.log("Handling delete:" + messageId);
|
113 |
|
|
}
|
114 |
917be067
|
Fantič
|
|
115 |
bb690a9a
|
Fantič
|
console.log("notes loading: " + notesLoading);
|
116 |
|
|
|
117 |
b225ffee
|
Fantič
|
return (
|
118 |
|
|
<Box width="90%" marginLeft="5%">
|
119 |
|
|
<VStack>
|
120 |
|
|
<HStack marginTop="5%">
|
121 |
|
|
<Box width="30%" justifyContent={"center"}>
|
122 |
|
|
<Popover // @ts-ignore
|
123 |
|
|
trigger={triggerProps => {
|
124 |
|
|
return <Button colorScheme="primary" {...triggerProps} onPress={() => setIsSortOpen(true)}>
|
125 |
|
|
Sort Options
|
126 |
|
|
</Button>;
|
127 |
|
|
}} isOpen={isSortOpen} onClose={() => setIsSortOpen(!isSortOpen)}>
|
128 |
|
|
<Popover.Content w="48">
|
129 |
|
|
<Popover.Arrow />
|
130 |
|
|
<Popover.CloseButton onPress={() => setIsSortOpen(false)} />
|
131 |
|
|
<Popover.Header>Sort Options</Popover.Header>
|
132 |
|
|
<Popover.Body>
|
133 |
|
|
<VStack>
|
134 |
|
|
<Button size="md" variant="outline" onPress={() => handleSortChanged("items")}
|
135 |
|
|
rightIcon={getSortIcon(sortSettings.items, "sm")}
|
136 |
|
|
>
|
137 |
|
|
Items</Button>
|
138 |
|
|
<Button size="md" variant="outline" marginTop={"5%"} onPress={() => handleSortChanged("date")}
|
139 |
|
|
rightIcon={getSortIcon(sortSettings.date, "sm")}>
|
140 |
|
|
Date</Button>
|
141 |
|
|
</VStack>
|
142 |
|
|
</Popover.Body>
|
143 |
|
|
<Popover.Footer justifyContent="flex-end">
|
144 |
|
|
<Button.Group space={2}>
|
145 |
|
|
<Button colorScheme="coolGray" variant="ghost" onPress={() => setIsSortOpen(false)}>
|
146 |
|
|
Cancel
|
147 |
|
|
</Button>
|
148 |
|
|
<Button colorScheme="success" onPress={() => { setIsSortOpen(false); getNotes() }}>
|
149 |
|
|
Save
|
150 |
|
|
</Button>
|
151 |
|
|
</Button.Group>
|
152 |
|
|
</Popover.Footer>
|
153 |
|
|
</Popover.Content>
|
154 |
|
|
</Popover>
|
155 |
|
|
</Box>
|
156 |
|
|
<VStack width="70%" space="0">
|
157 |
|
|
<Flex direction="row" alignItems="center" justify="flex-end">
|
158 |
|
|
<Text>My comments</Text>
|
159 |
bb690a9a
|
Fantič
|
<Switch isChecked={myCommentsCheck} onValueChange={() => {if(!notesLoading) setMyCommentsCheck(!myCommentsCheck)}} size="md" />
|
160 |
b225ffee
|
Fantič
|
</Flex>
|
161 |
|
|
<Flex direction="row" alignItems="center" justify="flex-end" marginTop="-7.5%">
|
162 |
|
|
<Text>General comments</Text>
|
163 |
bb690a9a
|
Fantič
|
<Switch isChecked={generalCommentsCheck} onValueChange={() => {if(!notesLoading) setGeneralCommentsCheck(!generalCommentsCheck)}} size="md" />
|
164 |
b225ffee
|
Fantič
|
</Flex>
|
165 |
|
|
</VStack>
|
166 |
|
|
</HStack>
|
167 |
|
|
<Box h={replyingTo != null ? "62.5%" : "67.5%"}>
|
168 |
bb690a9a
|
Fantič
|
{
|
169 |
|
|
notesLoading ? (<LoadingBox text="Loading notes"/>)
|
170 |
|
|
:
|
171 |
|
|
(<NotesListView notes={notes} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} />)
|
172 |
|
|
}
|
173 |
b225ffee
|
Fantič
|
</Box>
|
174 |
|
|
{replyingTo != null &&
|
175 |
|
|
<Flex direction="row" alignItems="center" justify="flex-end" h="5%" marginRight="10%">
|
176 |
|
|
<Text>Replying to {replyingTo.userName}</Text>
|
177 |
|
|
<IconButton onPress={() => setReplyingTo(null)} size="sm" icon={<CloseIcon />} marginLeft="-1%">
|
178 |
|
|
</IconButton>
|
179 |
|
|
</Flex>
|
180 |
|
|
}
|
181 |
|
|
<HStack h={replyingTo != null ? "20%" : "15%"} marginTop={replyingTo != null ? "0%" : "5%"}>
|
182 |
|
|
<TextArea placeholder="Add comment" width="90%" autoCompleteType={undefined} ></TextArea>
|
183 |
|
|
<VStack>
|
184 |
|
|
<Box h={replyingTo != null ? "30%" : "45%"}></Box>
|
185 |
|
|
<Box marginLeft="2">
|
186 |
|
|
<Button startIcon={<MessageIcon color="#FFF" />}></Button>
|
187 |
|
|
</Box>
|
188 |
|
|
</VStack>
|
189 |
|
|
</HStack>
|
190 |
|
|
</VStack>
|
191 |
|
|
<ConfirmDialog {...confirmDialog} isShown={confirmDialog != null} cancelRef={cancelRef} />
|
192 |
|
|
</Box>
|
193 |
917be067
|
Fantič
|
);
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
export default NotesViewPage;
|