-
-
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.
feat(home): implement sort by publish date #22
- Loading branch information
Showing
14 changed files
with
390 additions
and
5 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
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
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
86 changes: 86 additions & 0 deletions
86
src/ui/components/pages/Home/TabActions/AllViewActions/AllViewSorting.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,86 @@ | ||
import React, { useState } from 'react'; | ||
import { IconButton, ListSubheader } from '@mui/material'; | ||
import { StyledMenu, CheckableMenuItem } from 'ui/components/shared'; | ||
import { useAppDispatch, useAppSelector } from 'store'; | ||
import SortIcon from '@mui/icons-material/Sort'; | ||
import { selectViewSorting } from 'store/selectors/settings'; | ||
import { setViewSorting } from 'store/reducers/settings'; | ||
import { HomeView, Nullable, ViewSorting } from 'types'; | ||
|
||
const options: { | ||
label: string; | ||
value: keyof ViewSorting; | ||
}[] = [ | ||
{ | ||
label: 'Publish date', | ||
value: 'publishDate', | ||
}, | ||
]; | ||
|
||
interface AllViewSortingProps {} | ||
|
||
function AllViewSorting(props: AllViewSortingProps) { | ||
const sorting = useAppSelector(selectViewSorting(HomeView.All)); | ||
const dispatch = useAppDispatch(); | ||
const [anchorEl, setAnchorEl] = useState<Nullable<HTMLElement>>(null); | ||
const open = Boolean(anchorEl); | ||
|
||
const handleClick = (event: React.MouseEvent<HTMLElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
|
||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
const handleSortToggle = (key: keyof ViewSorting) => { | ||
dispatch( | ||
setViewSorting({ | ||
view: HomeView.All, | ||
sorting: { | ||
[key]: !sorting[key], | ||
}, | ||
}), | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
<IconButton | ||
id="sort-button" | ||
aria-label="sort" | ||
aria-controls={open ? 'sort-menu' : undefined} | ||
aria-expanded={open ? 'true' : undefined} | ||
aria-haspopup="true" | ||
onClick={handleClick} | ||
> | ||
<SortIcon /> | ||
</IconButton> | ||
<StyledMenu | ||
id="sort-menu" | ||
MenuListProps={{ | ||
'aria-labelledby': 'sort-button', | ||
dense: true, | ||
subheader: <ListSubheader component="div">Sort by</ListSubheader>, | ||
}} | ||
anchorEl={anchorEl} | ||
open={open} | ||
onClose={handleClose} | ||
transformOrigin={{ horizontal: 'right', vertical: 'top' }} | ||
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }} | ||
> | ||
{options.map(({ label, value }, index) => ( | ||
<CheckableMenuItem | ||
key={index} | ||
checked={!!sorting[value]} | ||
onClick={() => handleSortToggle(value)} | ||
> | ||
{label} | ||
</CheckableMenuItem> | ||
))} | ||
</StyledMenu> | ||
</> | ||
); | ||
} | ||
|
||
export default AllViewSorting; |
21 changes: 21 additions & 0 deletions
21
src/ui/components/pages/Home/TabActions/AllViewActions/index.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,21 @@ | ||
import React from 'react'; | ||
import { Box } from '@mui/material'; | ||
import AllViewSorting from './AllViewSorting'; | ||
|
||
interface AllViewActionsProps {} | ||
|
||
function AllViewActions(props: AllViewActionsProps) { | ||
return ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: 2, | ||
}} | ||
> | ||
<AllViewSorting /> | ||
</Box> | ||
); | ||
} | ||
|
||
export default AllViewActions; |
86 changes: 86 additions & 0 deletions
86
src/ui/components/pages/Home/TabActions/RecentViewActions/RecentViewSorting.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,86 @@ | ||
import React, { useState } from 'react'; | ||
import { IconButton, ListSubheader } from '@mui/material'; | ||
import { StyledMenu, CheckableMenuItem } from 'ui/components/shared'; | ||
import { useAppDispatch, useAppSelector } from 'store'; | ||
import SortIcon from '@mui/icons-material/Sort'; | ||
import { selectViewSorting } from 'store/selectors/settings'; | ||
import { setViewSorting } from 'store/reducers/settings'; | ||
import { HomeView, Nullable, ViewSorting } from 'types'; | ||
|
||
const options: { | ||
label: string; | ||
value: keyof ViewSorting; | ||
}[] = [ | ||
{ | ||
label: 'Publish date', | ||
value: 'publishDate', | ||
}, | ||
]; | ||
|
||
interface RecentViewSortingProps {} | ||
|
||
function RecentViewSorting(props: RecentViewSortingProps) { | ||
const sorting = useAppSelector(selectViewSorting(HomeView.Recent)); | ||
const dispatch = useAppDispatch(); | ||
const [anchorEl, setAnchorEl] = useState<Nullable<HTMLElement>>(null); | ||
const open = Boolean(anchorEl); | ||
|
||
const handleClick = (event: React.MouseEvent<HTMLElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
|
||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
const handleSortToggle = (key: keyof ViewSorting) => { | ||
dispatch( | ||
setViewSorting({ | ||
view: HomeView.Recent, | ||
sorting: { | ||
[key]: !sorting[key], | ||
}, | ||
}), | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
<IconButton | ||
id="sort-button" | ||
aria-label="sort" | ||
aria-controls={open ? 'sort-menu' : undefined} | ||
aria-expanded={open ? 'true' : undefined} | ||
aria-haspopup="true" | ||
onClick={handleClick} | ||
> | ||
<SortIcon /> | ||
</IconButton> | ||
<StyledMenu | ||
id="sort-menu" | ||
MenuListProps={{ | ||
'aria-labelledby': 'sort-button', | ||
dense: true, | ||
subheader: <ListSubheader component="div">Sort by</ListSubheader>, | ||
}} | ||
anchorEl={anchorEl} | ||
open={open} | ||
onClose={handleClose} | ||
transformOrigin={{ horizontal: 'right', vertical: 'top' }} | ||
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }} | ||
> | ||
{options.map(({ label, value }, index) => ( | ||
<CheckableMenuItem | ||
key={index} | ||
checked={!!sorting[value]} | ||
onClick={() => handleSortToggle(value)} | ||
> | ||
{label} | ||
</CheckableMenuItem> | ||
))} | ||
</StyledMenu> | ||
</> | ||
); | ||
} | ||
|
||
export default RecentViewSorting; |
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.