Revize 9814562f
Přidáno uživatelem Fantič před více než 1 rok
src/pages/NotesViewPage.tsx | ||
---|---|---|
30 | 30 |
const toast = useToast(); |
31 | 31 |
|
32 | 32 |
useEffect(() => { |
33 |
if (lastError) {
|
|
34 |
toast.closeAll()
|
|
35 |
toast.show({
|
|
36 |
render: ({
|
|
37 |
id
|
|
38 |
}) => {
|
|
39 |
return <ErrorToast headerText={"Error"} text={lastError} onClose={() => toast.close(id)} />;
|
|
40 |
},
|
|
41 |
duration: 3000
|
|
42 |
});
|
|
43 |
}
|
|
33 |
if (lastError) { |
|
34 |
toast.closeAll() |
|
35 |
toast.show({ |
|
36 |
render: ({ |
|
37 |
id |
|
38 |
}) => { |
|
39 |
return <ErrorToast headerText={"Error"} text={lastError} onClose={() => toast.close(id)} />; |
|
40 |
}, |
|
41 |
duration: 3000 |
|
42 |
}); |
|
43 |
} |
|
44 | 44 |
}, [lastError]) |
45 | 45 |
|
46 | 46 |
const [sortSettings, setSortSettings] = useState({ |
... | ... | |
48 | 48 |
date: SortOptions.None |
49 | 49 |
}); |
50 | 50 |
|
51 |
console.log(sortSettings) |
|
52 |
|
|
51 | 53 |
const handleSortChanged = useCallback((key: "items" | "date", sortSettings: any) => { |
52 | 54 |
let currentState = sortSettings[key]; |
55 |
let otherKey = "items" |
|
56 |
|
|
57 |
if (key == "items") { |
|
58 |
otherKey = "date" |
|
59 |
} |
|
60 |
|
|
53 | 61 |
if (currentState == SortOptions.None) { |
54 | 62 |
setSortSettings({ |
55 | 63 |
...sortSettings, |
56 |
[key]: SortOptions.Asc |
|
64 |
[key]: SortOptions.Asc, |
|
65 |
[otherKey]: SortOptions.None |
|
57 | 66 |
}) |
58 | 67 |
} |
59 | 68 |
else if (currentState == SortOptions.Asc) { |
60 | 69 |
setSortSettings({ |
61 | 70 |
...sortSettings, |
62 |
[key]: SortOptions.Desc |
|
71 |
[key]: SortOptions.Desc, |
|
72 |
[otherKey]: SortOptions.None |
|
63 | 73 |
}) |
64 | 74 |
} |
65 | 75 |
else { |
66 | 76 |
setSortSettings({ |
67 | 77 |
...sortSettings, |
68 |
[key]: SortOptions.None |
|
78 |
[key]: SortOptions.None, |
|
79 |
[otherKey]: SortOptions.None |
|
69 | 80 |
}) |
70 | 81 |
} |
71 | 82 |
}, [setSortSettings]); |
72 | 83 |
|
73 |
const getSortIcon = (sortOption: SortOptions, size: string) => { |
|
84 |
const getSortIcon = (sortOption: SortOptions, size: string, color?: string) => {
|
|
74 | 85 |
switch (sortOption) { |
75 | 86 |
case SortOptions.Asc: |
76 |
return <ChevronUpIcon size={size} />; |
|
87 |
return <ChevronUpIcon size={size} color={color} />;
|
|
77 | 88 |
case SortOptions.Desc: |
78 |
return <ChevronDownIcon size={size} />; |
|
89 |
return <ChevronDownIcon size={size} color={color} />;
|
|
79 | 90 |
default: |
80 |
return <MinusIcon size={size} />; |
|
91 |
return <MinusIcon size={size} color={color} />;
|
|
81 | 92 |
} |
82 | 93 |
}; |
83 | 94 |
|
... | ... | |
112 | 123 |
// creating new comment |
113 | 124 |
toast.show({ |
114 | 125 |
render: ({ |
115 |
id
|
|
126 |
id |
|
116 | 127 |
}) => { |
117 |
return <InfoToast text={"Adding note"} onClose={() => toast.close(id)} />;
|
|
128 |
return <InfoToast text={"Adding note"} onClose={() => toast.close(id)} />;
|
|
118 | 129 |
}, |
119 | 130 |
duration: 2000 |
120 |
}); |
|
131 |
});
|
|
121 | 132 |
if (replyingTo != null) { |
122 | 133 |
dispatch(createNote({ |
123 | 134 |
newNote: { note: newComment, reply_to: replyingTo.messageId } as Note |
... | ... | |
134 | 145 |
|
135 | 146 |
|
136 | 147 |
return ( |
137 |
<Box marginLeft={2.5} marginRight={2.5} marginTop={2.5}>
|
|
148 |
<Box> |
|
138 | 149 |
<VStack> |
139 |
<HStack height={75} justifyContent="space-between"> |
|
150 |
<HStack height={75} justifyContent="space-between" paddingLeft={2.5} paddingRight={2.5} marginTop={2.5}>
|
|
140 | 151 |
<Box justifyContent={"center"}> |
141 | 152 |
<Popover // @ts-ignore |
142 | 153 |
trigger={triggerProps => { |
143 |
return <Button colorScheme="primary" {...triggerProps} onPress={() => setIsSortOpen(true)}> |
|
144 |
Sort Options |
|
154 |
return <Button width={150} backgroundColor="#F4DFAB" {...triggerProps} onPress={() => setIsSortOpen(true)} |
|
155 |
borderRadius={7} |
|
156 |
rightIcon={(sortSettings.date != SortOptions.None || sortSettings.items != SortOptions.None) ? (getSortIcon(sortSettings.date != SortOptions.None ? sortSettings.date : sortSettings.items, "xs", "#654B07")) : undefined} |
|
157 |
> |
|
158 |
<Text fontSize={14} color="#654B07"> |
|
159 |
Sort {(sortSettings.date != SortOptions.None || sortSettings.items != SortOptions.None) ? (sortSettings.date != SortOptions.None ? "by date" : "by items") : ""} |
|
160 |
</Text> |
|
145 | 161 |
</Button>; |
146 | 162 |
}} isOpen={isSortOpen} onClose={() => setIsSortOpen(!isSortOpen)}> |
147 | 163 |
<Popover.Content w="48"> |
148 | 164 |
<Popover.Arrow /> |
149 | 165 |
<Popover.CloseButton onPress={() => setIsSortOpen(false)} /> |
150 |
<Popover.Header>Sort Options</Popover.Header>
|
|
166 |
<Popover.Header><Text fontSize={"md"} color="#654B07">Sort Options</Text></Popover.Header>
|
|
151 | 167 |
<Popover.Body> |
152 | 168 |
<VStack> |
153 | 169 |
<Button size="md" variant="outline" onPress={() => handleSortChanged("items", sortSettings)} |
154 |
rightIcon={getSortIcon(sortSettings.items, "sm")} |
|
170 |
rightIcon={getSortIcon(sortSettings.items, "sm", "#654B07")}
|
|
155 | 171 |
> |
156 | 172 |
Items</Button> |
157 | 173 |
<Button size="md" variant="outline" marginTop={"5%"} onPress={() => handleSortChanged("date", sortSettings)} |
158 |
rightIcon={getSortIcon(sortSettings.date, "sm")}> |
|
174 |
rightIcon={getSortIcon(sortSettings.date, "sm", "#654B07")}>
|
|
159 | 175 |
Date</Button> |
160 | 176 |
</VStack> |
161 | 177 |
</Popover.Body> |
... | ... | |
164 | 180 |
<Button colorScheme="coolGray" variant="ghost" onPress={() => setIsSortOpen(false)}> |
165 | 181 |
Cancel |
166 | 182 |
</Button> |
167 |
<Button colorScheme="success" onPress={() => { setIsSortOpen(false); getNotes() }}> |
|
168 |
Save |
|
183 |
<Button backgroundColor={"#F4DFAB"} onPress={() => { setIsSortOpen(false); getNotes() }}> |
|
184 |
<Text color="#654B07"> |
|
185 |
Save |
|
186 |
</Text> |
|
169 | 187 |
</Button> |
170 | 188 |
</Button.Group> |
171 | 189 |
</Popover.Footer> |
Také k dispozici: Unified diff
re #10895: NoteViewPage: Sort refactor