even more continue watching

This commit is contained in:
James Hawkins 2021-08-06 17:57:58 +01:00
parent 764d673897
commit 7a85f05c47
4 changed files with 20 additions and 11 deletions

View File

@ -3,14 +3,15 @@ import { TypeSelector } from './TypeSelector';
import { NumberSelector } from './NumberSelector';
import './EpisodeSelector.css'
export function EpisodeSelector({ setSelectedSeason, setEpisode, seasons, selectedSeason, season, episodes, currentSeason, currentEpisode, streamData }) {
export function EpisodeSelector({ setSelectedSeason, selectedSeason, setEpisode, seasons, episodes, currentSeason, currentEpisode, streamData }) {
const choices = episodes ? episodes.map(v => {
let progressData = JSON.parse(localStorage.getItem('video-progress') || "{}")
let currentlyAt = 0;
let totalDuration = 0;
const progress = progressData?.[streamData.source]?.[streamData.show]?.[streamData.slug]?.[`${season}-${v}`]
const progress = progressData?.[streamData.source]?.[streamData.type]?.[streamData.slug]?.[`${selectedSeason}-${v}`]
if (progress) {
currentlyAt = progress.currentlyAt
totalDuration = progress.totalDuration

View File

@ -6,13 +6,14 @@ import { PercentageOverlay } from './PercentageOverlay'
// title: string
// onClick: () => void
export function MovieRow(props) {
const progressData = JSON.parse(localStorage.getItem("video-progress") || "{}")
let progress;
let percentage = null;
if(props.type === "movie") {
if (props.type === "movie") {
progress = progressData?.[props.source]?.movie?.[props.slug]?.full
if(progress) {
if (progress) {
percentage = Math.floor((progress.currentlyAt / progress.totalDuration) * 100)
}
}
@ -20,13 +21,15 @@ export function MovieRow(props) {
return (
<div className="movieRow" onClick={() => props.onClick && props.onClick()}>
<div className="left">
{props.title} <span className="seasonEpisodeSubtitle">{props.place ? ` — Season ${props.place.season}: episode ${props.place.episode}` : ''}</span>&nbsp;
{props.title}<span className="seasonEpisodeSubtitle">{props.place ? ` - S${props.place.season}:E${props.place.episode}` : ''}</span>&nbsp;
<span className="year">({props.year})</span>
</div>
<div className="watch">
<p>Watch {props.type}</p>
<Arrow/>
</div>
<PercentageOverlay percentage={props.percentage || percentage} />
</div>
)

View File

@ -1,4 +1,4 @@
import React, { useCallback } from 'react'
import React from 'react'
import { useRouteMatch, useHistory } from 'react-router-dom'
import { Helmet } from 'react-helmet';
import { Title } from '../components/Title'

View File

@ -56,7 +56,6 @@ export function SearchView() {
let realUrl = '';
if (type === "movie") {
// getStreamUrl(slug, type, source, season, episode)
const { url } = await getStreamUrl(slug, type, source);
if (url === '') {
@ -65,6 +64,8 @@ export function SearchView() {
realUrl = url;
}
console.log(year)
setProgress(maxSteps);
setStreamUrl(realUrl);
setStreamData({
@ -227,12 +228,16 @@ export function SearchView() {
{/* Continue watching */}
{continueWatching.length > 0 && page === 'watching' ? <Card>
<Title>Continue watching</Title>
{console.log(continueWatching)}
{continueWatching?.map((v, i) => (
<MovieRow key={i} title={v.data.meta.title} slug={v.data.meta.slug} type={v.type} year={v.data.meta.year} source={v.source} place={v.data.show} percentage={v.percentageDone} onClick={() => {
history.push(`${routeMatch.url}/${v.source}/${v.data.meta.title}/${v.slug}`)
if (v.type === 'show') {
history.push(`${routeMatch.url}/${v.source}/${v.data.meta.title}/${v.slug}/season/${v.data.show.season}/episode/${v.data.show.episode}`)
} else {
history.push(`${routeMatch.url}/${v.source}/${v.data.meta.title}/${v.slug}`)
}
setShowingOptions(false)
getStream(v.data.meta.title, v.data.meta.slug, v.type, v.source, v.year)
getStream(v.data.meta.title, v.data.meta.slug, v.type, v.source, v.data.meta.year)
}} />
))}
</Card> : <React.Fragment></React.Fragment>}