-
-
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): add extra video actions to the display options
- Loading branch information
Showing
8 changed files
with
271 additions
and
82 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
102 changes: 102 additions & 0 deletions
102
src/ui/components/pages/Home/DisplayOptionsDialog/ActiveViews.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,102 @@ | ||
import React, { forwardRef, useImperativeHandle, useState } from 'react'; | ||
import { | ||
FormControl, | ||
FormControlLabel, | ||
FormGroup, | ||
FormLabel, | ||
Switch, | ||
} from '@mui/material'; | ||
import { useAppSelector } from 'store'; | ||
import { selectHiddenViews } from 'store/selectors/settings'; | ||
import { HomeView } from 'types'; | ||
|
||
interface ActiveViewsProps {} | ||
|
||
interface View { | ||
label: string; | ||
value: HomeView; | ||
hidden: boolean; | ||
} | ||
|
||
export interface ActiveViewsRef { | ||
reset: () => void; | ||
getViews: () => View[]; | ||
setViews: (views: View[]) => void; | ||
} | ||
|
||
const ActiveViews = forwardRef<ActiveViewsRef, ActiveViewsProps>( | ||
(props, ref) => { | ||
const hiddenViews = useAppSelector(selectHiddenViews); | ||
const initialViews: View[] = [ | ||
{ | ||
label: 'All', | ||
value: HomeView.All, | ||
hidden: hiddenViews.includes(HomeView.All), | ||
}, | ||
{ | ||
label: 'Recent', | ||
value: HomeView.Recent, | ||
hidden: hiddenViews.includes(HomeView.Recent), | ||
}, | ||
{ | ||
label: 'Watch Later', | ||
value: HomeView.WatchLater, | ||
hidden: hiddenViews.includes(HomeView.WatchLater), | ||
}, | ||
]; | ||
const [views, setViews] = useState(initialViews); | ||
|
||
useImperativeHandle( | ||
ref, | ||
() => ({ | ||
reset: () => setViews(initialViews), | ||
getViews: () => views, | ||
setViews, | ||
}), | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[views], | ||
); | ||
|
||
const handleToggle = (target: View) => { | ||
setViews((state) => | ||
state.map((view) => | ||
view.value === target.value | ||
? { | ||
...view, | ||
hidden: !view.hidden, | ||
} | ||
: view, | ||
), | ||
); | ||
}; | ||
|
||
return ( | ||
<FormControl | ||
component="fieldset" | ||
variant="standard" | ||
focused={false} | ||
fullWidth | ||
> | ||
<FormLabel component="legend">Active views</FormLabel> | ||
<FormGroup> | ||
{views.map((view) => ( | ||
<FormControlLabel | ||
onClick={() => handleToggle(view)} | ||
key={view.value} | ||
control={ | ||
<Switch | ||
color="secondary" | ||
checked={!view.hidden} | ||
name={view.value} | ||
/> | ||
} | ||
label={view.label} | ||
/> | ||
))} | ||
</FormGroup> | ||
</FormControl> | ||
); | ||
}, | ||
); | ||
|
||
export default ActiveViews; |
93 changes: 93 additions & 0 deletions
93
src/ui/components/pages/Home/DisplayOptionsDialog/ExtraVideoActions.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,93 @@ | ||
import React, { forwardRef, useImperativeHandle, useState } from 'react'; | ||
import { | ||
FormControl, | ||
FormControlLabel, | ||
FormGroup, | ||
FormLabel, | ||
Switch, | ||
} from '@mui/material'; | ||
import { useAppSelector } from 'store'; | ||
import { selectExtraVideoActions } from 'store/selectors/settings'; | ||
import { ExtraVideoAction } from 'types'; | ||
|
||
interface ExtraVideoActionsProps {} | ||
|
||
interface Action { | ||
label: string; | ||
value: ExtraVideoAction; | ||
active: boolean; | ||
} | ||
|
||
export interface ExtraVideoActionsRef { | ||
reset: () => void; | ||
getActions: () => Action[]; | ||
setActions: (actions: Action[]) => void; | ||
} | ||
|
||
const ExtraVideoActions = forwardRef< | ||
ExtraVideoActionsRef, | ||
ExtraVideoActionsProps | ||
>((props, ref) => { | ||
const extraVideoActions = useAppSelector(selectExtraVideoActions); | ||
const initialActions: Action[] = [ | ||
{ | ||
label: 'Copy link to clipboard', | ||
value: ExtraVideoAction.CopyLink, | ||
active: extraVideoActions.includes(ExtraVideoAction.CopyLink), | ||
}, | ||
]; | ||
const [actions, setActions] = useState(initialActions); | ||
|
||
useImperativeHandle( | ||
ref, | ||
() => ({ | ||
reset: () => setActions(initialActions), | ||
getActions: () => actions, | ||
setActions, | ||
}), | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[actions], | ||
); | ||
|
||
const handleToggle = (target: Action) => { | ||
setActions((state) => | ||
state.map((action) => | ||
action.value === target.value | ||
? { | ||
...action, | ||
active: !action.active, | ||
} | ||
: action, | ||
), | ||
); | ||
}; | ||
|
||
return ( | ||
<FormControl | ||
component="fieldset" | ||
variant="standard" | ||
focused={false} | ||
fullWidth | ||
> | ||
<FormLabel component="legend">Extra video actions</FormLabel> | ||
<FormGroup> | ||
{actions.map((action) => ( | ||
<FormControlLabel | ||
onClick={() => handleToggle(action)} | ||
key={action.value} | ||
control={ | ||
<Switch | ||
color="secondary" | ||
checked={action.active} | ||
name={action.value} | ||
/> | ||
} | ||
label={action.label} | ||
/> | ||
))} | ||
</FormGroup> | ||
</FormControl> | ||
); | ||
}); | ||
|
||
export default ExtraVideoActions; |
Oops, something went wrong.