2021-07-15 00:09:42 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { TypeSelector } from './TypeSelector';
|
|
|
|
import { NumberSelector } from './NumberSelector';
|
|
|
|
import './EpisodeSelector.css'
|
|
|
|
|
2021-07-21 00:49:33 +02:00
|
|
|
export function EpisodeSelector({ setSeason, setEpisode, seasons, season, episodes, currentSeason, currentEpisode, slug, source }) {
|
2021-07-15 21:04:47 +02:00
|
|
|
|
|
|
|
const choices = episodes.map(v => {
|
|
|
|
|
|
|
|
let progressData = JSON.parse(localStorage.getItem('video-progress') || "{}")
|
|
|
|
|
|
|
|
let currentlyAt = 0;
|
|
|
|
let totalDuration = 0;
|
|
|
|
|
2021-07-21 00:49:33 +02:00
|
|
|
const progress = progressData?.[source]?.show?.slug?.[`${season}-${v}`]
|
2021-07-15 21:04:47 +02:00
|
|
|
if(progress) {
|
|
|
|
currentlyAt = progress.currentlyAt
|
|
|
|
totalDuration = progress.totalDuration
|
|
|
|
}
|
|
|
|
|
|
|
|
const percentage = Math.round((currentlyAt / totalDuration) * 100)
|
|
|
|
|
|
|
|
return {
|
|
|
|
value: v.toString(),
|
|
|
|
label: v,
|
|
|
|
percentage
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-07-15 00:09:42 +02:00
|
|
|
return (
|
2021-07-15 18:28:00 +02:00
|
|
|
<div className="episodeSelector">
|
2021-07-15 00:09:42 +02:00
|
|
|
<TypeSelector setType={setSeason} choices={seasons.map(v=>({ value: v.toString(), label: `Season ${v}`}))} selected={currentSeason}/><br></br>
|
2021-07-15 21:04:47 +02:00
|
|
|
<NumberSelector setType={(e) => setEpisode({episode: e, season: currentSeason})} choices={choices} selected={currentEpisode.season === currentSeason?currentEpisode.episode:null}/>
|
2021-07-15 00:09:42 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|