Skip to content

Commit

Permalink
refactor: use a common ViewSorting component
Browse files Browse the repository at this point in the history
  • Loading branch information
AXeL-dev committed Sep 19, 2022
1 parent 28dced7 commit 6faeb8e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 183 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Box } from '@mui/material';
import AllViewSorting from './AllViewSorting';
import { HomeView } from 'types';
import ViewSorting from '../ViewSorting';

interface AllViewActionsProps {}

Expand All @@ -13,7 +14,7 @@ function AllViewActions(props: AllViewActionsProps) {
gap: 2,
}}
>
<AllViewSorting />
<ViewSorting view={HomeView.All} />
</Box>
);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Box } from '@mui/material';
import RecentViewFilters from './RecentViewFilters';
import RecentVideosSeniority from './RecentVideosSeniority';
import RecentViewOptions from './RecentViewOptions';
import RecentViewSorting from './RecentViewSorting';
import ViewSorting from '../ViewSorting';
import { HomeView } from 'types';

interface RecentViewActionsProps {
videosCount: number;
Expand All @@ -20,7 +21,7 @@ function RecentViewActions(props: RecentViewActionsProps) {
gap: 2,
}}
>
<RecentViewSorting />
<ViewSorting view={HomeView.Recent} />
<RecentViewFilters />
<RecentVideosSeniority />
{videosCount > 0 ? <RecentViewOptions /> : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ const options: {
},
];

interface AllViewSortingProps {}
interface DefaultViewSortingProps {
view: HomeView;
}

function AllViewSorting(props: AllViewSortingProps) {
const sorting = useAppSelector(selectViewSorting(HomeView.All));
function DefaultViewSorting(props: DefaultViewSortingProps) {
const { view } = props;
const sorting = useAppSelector(selectViewSorting(view));
const dispatch = useAppDispatch();
const [anchorEl, setAnchorEl] = useState<Nullable<HTMLElement>>(null);
const open = Boolean(anchorEl);
Expand All @@ -36,7 +39,7 @@ function AllViewSorting(props: AllViewSortingProps) {
const handleSortToggle = (key: keyof ViewSorting) => {
dispatch(
setViewSorting({
view: HomeView.All,
view,
sorting: {
[key]: !sorting[key],
},
Expand Down Expand Up @@ -83,4 +86,4 @@ function AllViewSorting(props: AllViewSortingProps) {
);
}

export default AllViewSorting;
export default DefaultViewSorting;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import { Box } from '@mui/material';
import WatchLaterViewFilters from './WatchLaterViewFilters';
import WatchLaterViewOptions from './WatchLaterViewOptions';
import WatchLaterViewSorting from './WatchLaterViewSorting';
import ViewSorting from '../ViewSorting';
import { HomeView } from 'types';

interface WatchLaterViewActionsProps {
videosCount: number;
Expand All @@ -19,7 +20,7 @@ function WatchLaterViewActions(props: WatchLaterViewActionsProps) {
gap: 2,
}}
>
<WatchLaterViewSorting />
<ViewSorting view={HomeView.WatchLater} />
<WatchLaterViewFilters />
{videosCount > 0 ? (
<WatchLaterViewOptions videosCount={videosCount} />
Expand Down

0 comments on commit 6faeb8e

Please sign in to comment.