-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(home): enhance nested menus UX
- Loading branch information
Showing
17 changed files
with
568 additions
and
514 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
|
||
export const childrenWithProps = (children: React.ReactNode, props: object) => | ||
React.Children.map(children, (child) => { | ||
if (React.isValidElement(child)) { | ||
return React.cloneElement(child, props); | ||
} | ||
return child; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/ui/components/pages/Home/TabActions/CommonMenus/ViewFilters.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { useMemo } from 'react'; | ||
import { ListItemIcon, ListItemText } from '@mui/material'; | ||
import { | ||
CheckableMenuItem, | ||
NestedMenuItem, | ||
NestedMenuItemProps, | ||
} from 'ui/components/shared'; | ||
import { useAppDispatch, useAppSelector } from 'store'; | ||
import { selectViewFilters } from 'store/selectors/settings'; | ||
import { setViewFilters } from 'store/reducers/settings'; | ||
import { HomeView, ViewFilters as Filters } from 'types'; | ||
import FilterAltIcon from '@mui/icons-material/FilterAlt'; | ||
|
||
export interface ViewFilterOption { | ||
label: string; | ||
value: keyof Filters; | ||
} | ||
|
||
interface ViewFiltersProps extends Omit<NestedMenuItemProps, 'label'> { | ||
view: HomeView; | ||
options: ViewFilterOption[]; | ||
} | ||
|
||
function ViewFilters(props: ViewFiltersProps) { | ||
const { view, options, ...rest } = props; | ||
const filters = useAppSelector(selectViewFilters(view)); | ||
const dispatch = useAppDispatch(); | ||
const activeFiltersCount = useMemo( | ||
() => Object.values(filters).filter(Boolean).length, | ||
[filters], | ||
); | ||
|
||
const handleFilterToggle = (key: keyof Filters) => { | ||
dispatch( | ||
setViewFilters({ | ||
view, | ||
filters: { | ||
[key]: !filters[key], | ||
}, | ||
}), | ||
); | ||
}; | ||
|
||
return ( | ||
<NestedMenuItem | ||
label={ | ||
<> | ||
<ListItemIcon> | ||
<FilterAltIcon /> | ||
</ListItemIcon> | ||
<ListItemText>Filters ({activeFiltersCount})</ListItemText> | ||
</> | ||
} | ||
{...rest} | ||
> | ||
{options.map(({ label, value }, index) => ( | ||
<CheckableMenuItem | ||
key={index} | ||
checked={!!filters[value]} | ||
onClick={() => handleFilterToggle(value)} | ||
> | ||
{label} | ||
</CheckableMenuItem> | ||
))} | ||
</NestedMenuItem> | ||
); | ||
} | ||
|
||
export default ViewFilters; |
72 changes: 72 additions & 0 deletions
72
src/ui/components/pages/Home/TabActions/CommonMenus/ViewSorting.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react'; | ||
import { ListItemIcon, ListItemText } from '@mui/material'; | ||
import { | ||
CheckableMenuItem, | ||
NestedMenuItem, | ||
NestedMenuItemProps, | ||
} from 'ui/components/shared'; | ||
import { useAppDispatch, useAppSelector } from 'store'; | ||
import { selectViewSorting } from 'store/selectors/settings'; | ||
import { setViewSorting } from 'store/reducers/settings'; | ||
import { HomeView, ViewSorting as Sorting } from 'types'; | ||
import SortIcon from '@mui/icons-material/Sort'; | ||
|
||
interface ViewSortingOption { | ||
label: string; | ||
value: keyof Sorting; | ||
} | ||
|
||
const options: ViewSortingOption[] = [ | ||
{ | ||
label: 'Publish date', | ||
value: 'publishDate', | ||
}, | ||
]; | ||
|
||
interface ViewSortingProps extends Omit<NestedMenuItemProps, 'label'> { | ||
view: HomeView; | ||
} | ||
|
||
function ViewSorting(props: ViewSortingProps) { | ||
const { view, ...rest } = props; | ||
const sorting = useAppSelector(selectViewSorting(view)); | ||
const dispatch = useAppDispatch(); | ||
|
||
const handleSortToggle = (key: keyof Sorting) => { | ||
dispatch( | ||
setViewSorting({ | ||
view, | ||
sorting: { | ||
[key]: !sorting[key], | ||
}, | ||
}), | ||
); | ||
}; | ||
|
||
return ( | ||
<NestedMenuItem | ||
label={ | ||
<> | ||
<ListItemIcon> | ||
<SortIcon /> | ||
</ListItemIcon> | ||
<ListItemText>Sort by</ListItemText> | ||
</> | ||
} | ||
isFirstItem | ||
{...rest} | ||
> | ||
{options.map(({ label, value }, index) => ( | ||
<CheckableMenuItem | ||
key={index} | ||
checked={!!sorting[value]} | ||
onClick={() => handleSortToggle(value)} | ||
> | ||
{label} | ||
</CheckableMenuItem> | ||
))} | ||
</NestedMenuItem> | ||
); | ||
} | ||
|
||
export default ViewSorting; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.