From 8098bc5c33e23344e488b1d56cb9c34bb5a7dce2 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 8 Dec 2024 13:57:40 +0100 Subject: [PATCH 1/3] fix: mark video as watched on player --- .../VideosList => common}/Video/Video.js | 20 +++++-------- .../VideoPlaceholder/VideoPlaceholder.js | 0 .../Video/VideoPlaceholder/index.js | 0 .../Video/VideoPlaceholder/styles.less | 0 .../VideosList => common}/Video/index.js | 0 .../VideosList => common}/Video/styles.less | 0 src/common/index.js | 2 ++ .../MetaDetails/VideosList/VideosList.js | 28 ++++++++++-------- src/routes/Player/Player.js | 9 +++--- src/routes/Player/VideosMenu/VideosMenu.js | 29 ++++++++++++------- 10 files changed, 48 insertions(+), 40 deletions(-) rename src/{routes/MetaDetails/VideosList => common}/Video/Video.js (94%) rename src/{routes/MetaDetails/VideosList => common}/Video/VideoPlaceholder/VideoPlaceholder.js (100%) rename src/{routes/MetaDetails/VideosList => common}/Video/VideoPlaceholder/index.js (100%) rename src/{routes/MetaDetails/VideosList => common}/Video/VideoPlaceholder/styles.less (100%) rename src/{routes/MetaDetails/VideosList => common}/Video/index.js (100%) rename src/{routes/MetaDetails/VideosList => common}/Video/styles.less (100%) diff --git a/src/routes/MetaDetails/VideosList/Video/Video.js b/src/common/Video/Video.js similarity index 94% rename from src/routes/MetaDetails/VideosList/Video/Video.js rename to src/common/Video/Video.js index 25b67aae9..f74b994eb 100644 --- a/src/routes/MetaDetails/VideosList/Video/Video.js +++ b/src/common/Video/Video.js @@ -4,15 +4,16 @@ const React = require('react'); const PropTypes = require('prop-types'); const classnames = require('classnames'); const { t } = require('i18next'); -const { useServices } = require('stremio/services'); const { useRouteFocused } = require('stremio-router'); const { default: Icon } = require('@stremio/stremio-icons/react'); -const { Button, Image, Popup, useBinaryState } = require('stremio/common'); +const Button = require('stremio/common/Button'); +const Image = require('stremio/common/Image'); +const Popup = require('stremio/common/Popup'); +const useBinaryState = require('stremio/common/useBinaryState'); const VideoPlaceholder = require('./VideoPlaceholder'); const styles = require('./styles'); -const Video = ({ className, id, title, thumbnail, episode, released, upcoming, watched, progress, scheduled, deepLinks, ...props }) => { - const { core } = useServices(); +const Video = ({ className, id, title, thumbnail, episode, released, upcoming, watched, progress, scheduled, deepLinks, onMarkVideoAsWatched, ...props }) => { const routeFocused = useRouteFocused(); const [menuOpen, , closeMenu, toggleMenu] = useBinaryState(false); const popupLabelOnMouseUp = React.useCallback((event) => { @@ -49,13 +50,7 @@ const Video = ({ className, id, title, thumbnail, episode, released, upcoming, w event.preventDefault(); event.stopPropagation(); closeMenu(); - core.transport.dispatch({ - action: 'MetaDetails', - args: { - action: 'MarkVideoAsWatched', - args: [{ id, released }, !watched] - } - }); + onMarkVideoAsWatched({ id, released }, watched); }, [id, released, watched]); const videoButtonOnClick = React.useCallback(() => { if (deepLinks) { @@ -198,7 +193,8 @@ Video.propTypes = { deepLinks: PropTypes.shape({ metaDetailsStreams: PropTypes.string, player: PropTypes.string - }) + }), + onMarkVideoAsWatched: PropTypes.func, }; module.exports = Video; diff --git a/src/routes/MetaDetails/VideosList/Video/VideoPlaceholder/VideoPlaceholder.js b/src/common/Video/VideoPlaceholder/VideoPlaceholder.js similarity index 100% rename from src/routes/MetaDetails/VideosList/Video/VideoPlaceholder/VideoPlaceholder.js rename to src/common/Video/VideoPlaceholder/VideoPlaceholder.js diff --git a/src/routes/MetaDetails/VideosList/Video/VideoPlaceholder/index.js b/src/common/Video/VideoPlaceholder/index.js similarity index 100% rename from src/routes/MetaDetails/VideosList/Video/VideoPlaceholder/index.js rename to src/common/Video/VideoPlaceholder/index.js diff --git a/src/routes/MetaDetails/VideosList/Video/VideoPlaceholder/styles.less b/src/common/Video/VideoPlaceholder/styles.less similarity index 100% rename from src/routes/MetaDetails/VideosList/Video/VideoPlaceholder/styles.less rename to src/common/Video/VideoPlaceholder/styles.less diff --git a/src/routes/MetaDetails/VideosList/Video/index.js b/src/common/Video/index.js similarity index 100% rename from src/routes/MetaDetails/VideosList/Video/index.js rename to src/common/Video/index.js diff --git a/src/routes/MetaDetails/VideosList/Video/styles.less b/src/common/Video/styles.less similarity index 100% rename from src/routes/MetaDetails/VideosList/Video/styles.less rename to src/common/Video/styles.less diff --git a/src/common/index.js b/src/common/index.js index 0605a3f9b..45eb0ef41 100644 --- a/src/common/index.js +++ b/src/common/index.js @@ -29,6 +29,7 @@ const Slider = require('./Slider'); const { default: TextInput } = require('./TextInput'); const { ToastProvider, useToast } = require('./Toast'); const { TooltipProvider, Tooltip } = require('./Tooltips'); +const Video = require('./Video'); const comparatorWithPriorities = require('./comparatorWithPriorities'); const CONSTANTS = require('./CONSTANTS'); const { withCoreSuspender, useCoreSuspender } = require('./CoreSuspender'); @@ -83,6 +84,7 @@ module.exports = { useToast, TooltipProvider, Tooltip, + Video, comparatorWithPriorities, CONSTANTS, withCoreSuspender, diff --git a/src/routes/MetaDetails/VideosList/VideosList.js b/src/routes/MetaDetails/VideosList/VideosList.js index 6013e4f01..3a446b44f 100644 --- a/src/routes/MetaDetails/VideosList/VideosList.js +++ b/src/routes/MetaDetails/VideosList/VideosList.js @@ -4,12 +4,13 @@ const React = require('react'); const PropTypes = require('prop-types'); const classnames = require('classnames'); const { t } = require('i18next'); -const { Image, SearchBar, Toggle } = require('stremio/common'); +const { useServices } = require('stremio/services'); +const { Image, SearchBar, Toggle, Video } = require('stremio/common'); const SeasonsBar = require('./SeasonsBar'); -const Video = require('./Video'); const styles = require('./styles'); const VideosList = ({ className, metaItem, libraryItem, season, seasonOnSelect, toggleNotifications }) => { + const { core } = useServices(); const showNotificationsToggle = React.useMemo(() => { return metaItem?.content?.content?.inLibrary && metaItem?.content?.content?.videos?.length; }, [metaItem]); @@ -59,6 +60,17 @@ const VideosList = ({ className, metaItem, libraryItem, season, seasonOnSelect, const searchInputOnChange = React.useCallback((event) => { setSearch(event.currentTarget.value); }, []); + + const onMarkVideoAsWatched = (video, watched) => { + core.transport.dispatch({ + action: 'MetaDetails', + args: { + action: 'MarkVideoAsWatched', + args: [video, !watched] + } + }); + }; + return (
{ @@ -120,16 +132,8 @@ const VideosList = ({ className, metaItem, libraryItem, season, seasonOnSelect, .map((video, index) => (