mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
refactor(EpisodePicker): simplify setting season and episode initial state
This commit is contained in:
parent
7a79e31f95
commit
6274115f8f
1 changed files with 2 additions and 8 deletions
|
|
@ -16,14 +16,8 @@ const EpisodePicker = ({ className, onSubmit }: Props) => {
|
|||
const splitPath = window.location.hash.split('/');
|
||||
const videoId = decodeURIComponent(splitPath[splitPath.length - 1]);
|
||||
const [, pathSeason, pathEpisode] = videoId ? videoId.split(':') : [];
|
||||
const [season, setSeason] = React.useState(() => {
|
||||
const initialSeason = isNaN(parseInt(pathSeason)) ? 0 : parseInt(pathSeason);
|
||||
return initialSeason;
|
||||
});
|
||||
const [episode, setEpisode] = React.useState(() => {
|
||||
const initialEpisode = isNaN(parseInt(pathEpisode)) ? 1 : parseInt(pathEpisode);
|
||||
return initialEpisode;
|
||||
});
|
||||
const [season, setSeason] = React.useState(isNaN(parseInt(pathSeason)) ? 0 : parseInt(pathSeason));
|
||||
const [episode, setEpisode] = React.useState(isNaN(parseInt(pathEpisode)) ? 1 : parseInt(pathEpisode));
|
||||
const handleSeasonChange = (value: number) => setSeason(!isNaN(value) ? value : 0);
|
||||
|
||||
const handleEpisodeChange = (value: number) => setEpisode(!isNaN(value) ? value : 1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue