Skip to content

Commit

Permalink
Feat: Add hidden select all/none extras section function
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon committed Aug 25, 2023
1 parent 1e161f8 commit 96d68ff
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/components/sections/extras/ModalContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,23 @@ function ModalContent(props) {
dispatch(changeExtraIds({ type, ids: [...currentIds, ...tmp] }));
}, [filteredItems, dispatch, currentIds, type]);

const toggleAllInSection = React.useCallback(
(sectionLabel) => {
const idsInSection = filteredItems
.find(([label]) => label === sectionLabel)[1]
.map(({ id }) => id);
const allSelected = idsInSection.every((id) => currentIds.includes(id));

if (allSelected) {
const filtered = currentIds.filter((id) => !idsInSection.includes(id));
dispatch(changeExtraIds({ type, ids: filtered }));
} else {
dispatch(changeExtraIds({ type, ids: [...currentIds, ...idsInSection] }));
}
},
[filteredItems, dispatch, currentIds, type],
);

const unselectAllVisible = React.useCallback(() => {
const tmp = filteredItems.flatMap((array) => array[1]).map(({ id }) => id);
const filtered = currentIds.filter((id) => !tmp.includes(id));
Expand Down Expand Up @@ -193,7 +210,15 @@ function ModalContent(props) {
return (
<div>
<FormControl sx={{ margin: 1, width: '100%' }} component="fieldset" variant="standard">
<FormLabel component="legend">
<FormLabel
component="legend"
sx={(theme) => ({
'&:hover': {
color: theme.palette.primary.main,
},
})}
onClick={() => toggleAllInSection(label)}
>
{
// i18next-extract-mark-context-next-line {{extraSection}}
t('extraSection', { context: label })
Expand Down

0 comments on commit 96d68ff

Please sign in to comment.