-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/continue-watching-shelf
- Loading branch information
Showing
12 changed files
with
196 additions
and
13 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { useHistory, useLocation } from 'react-router'; | ||
import React, { useContext, useState } from 'react'; | ||
import type { Config } from 'types/Config'; | ||
import type { PlaylistItem } from 'types/playlist'; | ||
|
||
import { copyToClipboard } from '../../utils/dom'; | ||
import useBlurImageUpdater from '../../hooks/useBlurImageUpdater'; | ||
import { ConfigContext } from '../../providers/ConfigProvider'; | ||
import VideoComponent from '../../components/Video/Video'; | ||
import { cardUrl, videoUrl } from '../../utils/formatting'; | ||
import usePlaylist from '../../hooks/usePlaylist'; | ||
import Shelf from '../Shelf/Shelf'; | ||
import { useFavorites } from '../../stores/FavoritesStore'; | ||
|
||
export type VideoType = 'movie' | 'series'; | ||
|
||
export type VideoProps = { | ||
playlistId: string; | ||
videoType: VideoType; | ||
episodeId?: string | null; | ||
mediaId?: string | null; | ||
}; | ||
|
||
const Video = ({ playlistId, videoType, episodeId, mediaId }: VideoProps): JSX.Element => { | ||
const history = useHistory(); | ||
const location = useLocation(); | ||
const { hasItem, saveItem, removeItem } = useFavorites(); | ||
const play = new URLSearchParams(location.search).get('play') === '1'; | ||
const config: Config = useContext(ConfigContext); | ||
const [hasShared, setHasShared] = useState<boolean>(false); | ||
const enableSharing: boolean = config.options.enableSharing === true; | ||
const posterFading: boolean = config.options.posterFading === true; | ||
|
||
const { isLoading, error, data: { playlist } = { playlist: [] } } = usePlaylist(playlistId); | ||
|
||
const updateBlurImage = useBlurImageUpdater(playlist); | ||
|
||
const getMovieItem = () => playlist.find((item) => item.mediaid === mediaId); | ||
const getSeriesItem = () => playlist[0]; | ||
const item = videoType === 'movie' ? getMovieItem() : getSeriesItem(); | ||
const isFavorited = !!item && hasItem(item); | ||
|
||
const startPlay = () => item && history.push(videoUrl(item, playlistId, true)); | ||
const goBack = () => item && history.push(videoUrl(item, playlistId, false)); | ||
|
||
const onCardClick = (item: PlaylistItem) => history.push(cardUrl(item)); | ||
const onCardHover = (item: PlaylistItem) => updateBlurImage(item.image); | ||
|
||
const onShareClick = (): void => { | ||
if (!item) return; | ||
|
||
if (typeof navigator.share === 'function') { | ||
navigator.share({ title: item.title, text: item.description, url: window.location.href }); | ||
} else { | ||
copyToClipboard(window.location.href); | ||
} | ||
setHasShared(true); | ||
setTimeout(() => setHasShared(false), 2000); | ||
}; | ||
|
||
//temp: | ||
console.info({ episodeId }); | ||
|
||
if (isLoading) return <p>Loading...</p>; | ||
if (error) return <p>Error loading list</p>; | ||
if (!playlist) return <p>List not found</p>; | ||
if (!item) return <p>Can not find medium</p>; | ||
|
||
return ( | ||
<VideoComponent | ||
item={item} | ||
play={play} | ||
startPlay={startPlay} | ||
goBack={goBack} | ||
poster={posterFading ? 'fading' : 'normal'} | ||
enableSharing={enableSharing} | ||
hasShared={hasShared} | ||
onShareClick={onShareClick} | ||
isFavorited={isFavorited} | ||
onFavoriteButtonClick={() => (isFavorited ? removeItem(item) : saveItem(item))} | ||
relatedShelf={ | ||
config.recommendationsPlaylist ? ( | ||
<Shelf | ||
playlistId={config.recommendationsPlaylist} | ||
onCardClick={onCardClick} | ||
onCardHover={onCardHover} | ||
relatedMediaId={item.mediaid} | ||
/> | ||
) : undefined | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export default Video; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
"share_video": "", | ||
"start_watching": "", | ||
"trailer": "", | ||
"copied_url": "", | ||
"watch_trailer": "" | ||
} |
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,10 @@ | ||
import React from 'react'; | ||
|
||
import createIcon from './Icon'; | ||
|
||
export default createIcon( | ||
'0 0 24 24', | ||
<g> | ||
<path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" /> | ||
</g>, | ||
); |
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