1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-21 14:47:41 +01:00
smov/src/components/EpisodeSelector.js

37 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-07-15 00:09:42 +02:00
import React from 'react';
import { TypeSelector } from './TypeSelector';
import { NumberSelector } from './NumberSelector';
2021-10-25 21:16:10 +02:00
import { VideoProgressStore } from '../lib/storage/VideoProgress'
2021-07-15 00:09:42 +02:00
import './EpisodeSelector.css'
2021-08-06 18:57:58 +02:00
export function EpisodeSelector({ setSelectedSeason, selectedSeason, setEpisode, seasons, episodes, currentSeason, currentEpisode, streamData }) {
const choices = episodes ? episodes.map(v => {
2021-10-25 21:16:10 +02:00
const progressData = VideoProgressStore.get();
let currentlyAt = 0;
let totalDuration = 0;
2021-08-06 18:57:58 +02:00
const progress = progressData?.[streamData.source]?.[streamData.type]?.[streamData.slug]?.[`${selectedSeason}-${v}`]
2021-08-06 17:54:09 +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-08-06 21:03:18 +02:00
<TypeSelector setType={setSelectedSeason} selected={selectedSeason} choices={seasons.map(v=>({ value: v.toString(), label: `Season ${v}`}))} /><br></br>
<NumberSelector setType={(e) => setEpisode({episode: e, season: selectedSeason})} choices={choices} selected={(selectedSeason.toString() === currentSeason) ? currentEpisode : null} />
2021-07-15 00:09:42 +02:00
</div>
)
}