From 23dfeb263b912f74679bb4df96a812f64b1caaca Mon Sep 17 00:00:00 2001 From: kKaskak <117831817+kKaskak@users.noreply.github.com> Date: Wed, 28 Feb 2024 14:16:15 +0200 Subject: [PATCH 1/7] feature: mark libItem as watched / unwatched --- src/common/LibItem/LibItem.js | 40 +++++++++++++++++++++++++++------ src/common/MetaItem/styles.less | 2 +- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/common/LibItem/LibItem.js b/src/common/LibItem/LibItem.js index d2858790d..a8071b278 100644 --- a/src/common/LibItem/LibItem.js +++ b/src/common/LibItem/LibItem.js @@ -6,19 +6,23 @@ const PropTypes = require('prop-types'); const MetaItem = require('stremio/common/MetaItem'); const { t } = require('i18next'); -const OPTIONS = [ - { label: 'LIBRARY_PLAY', value: 'play' }, - { label: 'LIBRARY_DETAILS', value: 'details' }, - { label: 'LIBRARY_RESUME_DISMISS', value: 'dismiss' }, - { label: 'LIBRARY_REMOVE', value: 'remove' }, -]; +const LibItem = ({ _id, removable, notifications, watched, ...props }) => { + + const OPTIONS = [ + { label: 'LIBRARY_PLAY', value: 'play' }, + { label: 'LIBRARY_DETAILS', value: 'details' }, + { label: 'LIBRARY_RESUME_DISMISS', value: 'dismiss' }, + { label: watched ? 'CTX_MARK_UNWATCHED' : 'CTX_MARK_WATCHED', value: 'watched' }, + { label: 'LIBRARY_REMOVE', value: 'remove' }, + ]; -const LibItem = ({ _id, removable, notifications, ...props }) => { const { core } = useServices(); + const newVideos = React.useMemo(() => { const count = notifications.items?.[_id]?.length ?? 0; return Math.min(Math.max(count, 0), 99); }, [_id, notifications]); + const options = React.useMemo(() => { return OPTIONS .filter(({ value }) => { @@ -27,6 +31,8 @@ const LibItem = ({ _id, removable, notifications, ...props }) => { return props.deepLinks && typeof props.deepLinks.player === 'string'; case 'details': return props.deepLinks && (typeof props.deepLinks.metaDetailsVideos === 'string' || typeof props.deepLinks.metaDetailsStreams === 'string'); + case 'watched': + return typeof _id === 'string' && watched !== null; case 'dismiss': return typeof _id === 'string' && props.progress !== null && !isNaN(props.progress); case 'remove': @@ -38,6 +44,7 @@ const LibItem = ({ _id, removable, notifications, ...props }) => { label: t(option.label) })); }, [_id, removable, props.progress, props.deepLinks]); + const optionOnSelect = React.useCallback((event) => { if (typeof props.optionOnSelect === 'function') { props.optionOnSelect(event); @@ -83,6 +90,22 @@ const LibItem = ({ _id, removable, notifications, ...props }) => { break; } + case 'watched': { + if (typeof _id === 'string') { + core.transport.dispatch({ + action: 'Ctx', + args: { + action: 'LibraryItemMarkAsWatched', + args: { + id: _id, + is_watched: !watched + } + } + }); + } + + break; + } case 'remove': { if (typeof _id === 'string') { core.transport.dispatch({ @@ -99,9 +122,11 @@ const LibItem = ({ _id, removable, notifications, ...props }) => { } } }, [_id, props.deepLinks, props.optionOnSelect]); + return ( Date: Wed, 28 Feb 2024 16:39:00 +0200 Subject: [PATCH 2/7] refactor: rendering of mark as watched option --- src/common/LibItem/LibItem.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/common/LibItem/LibItem.js b/src/common/LibItem/LibItem.js index a8071b278..67e3da0db 100644 --- a/src/common/LibItem/LibItem.js +++ b/src/common/LibItem/LibItem.js @@ -32,7 +32,7 @@ const LibItem = ({ _id, removable, notifications, watched, ...props }) => { case 'details': return props.deepLinks && (typeof props.deepLinks.metaDetailsVideos === 'string' || typeof props.deepLinks.metaDetailsStreams === 'string'); case 'watched': - return typeof _id === 'string' && watched !== null; + return props.deepLinks && (typeof props.deepLinks.metaDetailsVideos === 'string' || typeof props.deepLinks.metaDetailsStreams === 'string'); case 'dismiss': return typeof _id === 'string' && props.progress !== null && !isNaN(props.progress); case 'remove': @@ -70,6 +70,22 @@ const LibItem = ({ _id, removable, notifications, watched, ...props }) => { break; } + case 'watched': { + if (typeof _id === 'string') { + core.transport.dispatch({ + action: 'Ctx', + args: { + action: 'LibraryItemMarkAsWatched', + args: { + id: _id, + is_watched: !watched + } + } + }); + } + + break; + } case 'dismiss': { if (typeof _id === 'string') { core.transport.dispatch({ @@ -90,22 +106,6 @@ const LibItem = ({ _id, removable, notifications, watched, ...props }) => { break; } - case 'watched': { - if (typeof _id === 'string') { - core.transport.dispatch({ - action: 'Ctx', - args: { - action: 'LibraryItemMarkAsWatched', - args: { - id: _id, - is_watched: !watched - } - } - }); - } - - break; - } case 'remove': { if (typeof _id === 'string') { core.transport.dispatch({ From b89c73a5093e4a3da7e580358a326e64791f8992 Mon Sep 17 00:00:00 2001 From: kKaskak <117831817+kKaskak@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:32:08 +0200 Subject: [PATCH 3/7] refactor: impl useMemo --- src/common/LibItem/LibItem.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/LibItem/LibItem.js b/src/common/LibItem/LibItem.js index 67e3da0db..870690e2e 100644 --- a/src/common/LibItem/LibItem.js +++ b/src/common/LibItem/LibItem.js @@ -8,13 +8,13 @@ const { t } = require('i18next'); const LibItem = ({ _id, removable, notifications, watched, ...props }) => { - const OPTIONS = [ + const OPTIONS = React.useMemo( () => [ { label: 'LIBRARY_PLAY', value: 'play' }, { label: 'LIBRARY_DETAILS', value: 'details' }, { label: 'LIBRARY_RESUME_DISMISS', value: 'dismiss' }, { label: watched ? 'CTX_MARK_UNWATCHED' : 'CTX_MARK_WATCHED', value: 'watched' }, { label: 'LIBRARY_REMOVE', value: 'remove' }, - ]; + ]); const { core } = useServices(); From 416dd1b5280f1455d311959a08884f3f80f8b547 Mon Sep 17 00:00:00 2001 From: kKaskak <117831817+kKaskak@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:32:46 +0200 Subject: [PATCH 4/7] refactor: typo --- src/common/LibItem/LibItem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/LibItem/LibItem.js b/src/common/LibItem/LibItem.js index 870690e2e..0b8e55c0e 100644 --- a/src/common/LibItem/LibItem.js +++ b/src/common/LibItem/LibItem.js @@ -8,7 +8,7 @@ const { t } = require('i18next'); const LibItem = ({ _id, removable, notifications, watched, ...props }) => { - const OPTIONS = React.useMemo( () => [ + const OPTIONS = React.useMemo(() => [ { label: 'LIBRARY_PLAY', value: 'play' }, { label: 'LIBRARY_DETAILS', value: 'details' }, { label: 'LIBRARY_RESUME_DISMISS', value: 'dismiss' }, From 81da07d231ea72ba56f4e46bb0d24539c29788e0 Mon Sep 17 00:00:00 2001 From: kKaskak <117831817+kKaskak@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:52:07 +0200 Subject: [PATCH 5/7] refactor: options --- src/common/LibItem/LibItem.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/common/LibItem/LibItem.js b/src/common/LibItem/LibItem.js index 0b8e55c0e..9753dc816 100644 --- a/src/common/LibItem/LibItem.js +++ b/src/common/LibItem/LibItem.js @@ -8,14 +8,6 @@ const { t } = require('i18next'); const LibItem = ({ _id, removable, notifications, watched, ...props }) => { - const OPTIONS = React.useMemo(() => [ - { label: 'LIBRARY_PLAY', value: 'play' }, - { label: 'LIBRARY_DETAILS', value: 'details' }, - { label: 'LIBRARY_RESUME_DISMISS', value: 'dismiss' }, - { label: watched ? 'CTX_MARK_UNWATCHED' : 'CTX_MARK_WATCHED', value: 'watched' }, - { label: 'LIBRARY_REMOVE', value: 'remove' }, - ]); - const { core } = useServices(); const newVideos = React.useMemo(() => { @@ -24,7 +16,14 @@ const LibItem = ({ _id, removable, notifications, watched, ...props }) => { }, [_id, notifications]); const options = React.useMemo(() => { - return OPTIONS + const optionsList = [ + { label: 'LIBRARY_PLAY', value: 'play' }, + { label: 'LIBRARY_DETAILS', value: 'details' }, + { label: 'LIBRARY_RESUME_DISMISS', value: 'dismiss' }, + { label: watched ? 'CTX_MARK_UNWATCHED' : 'CTX_MARK_WATCHED', value: 'watched' }, + { label: 'LIBRARY_REMOVE', value: 'remove' }, + ]; + return optionsList .filter(({ value }) => { switch (value) { case 'play': From 0547b1675e8563ed88a2c197b4964c3f4cb4108b Mon Sep 17 00:00:00 2001 From: kKaskak <117831817+kKaskak@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:56:38 +0200 Subject: [PATCH 6/7] refactor: chain the elements that are returned --- src/common/LibItem/LibItem.js | 39 ++++++++++++++++------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/common/LibItem/LibItem.js b/src/common/LibItem/LibItem.js index 9753dc816..88717c64c 100644 --- a/src/common/LibItem/LibItem.js +++ b/src/common/LibItem/LibItem.js @@ -16,32 +16,29 @@ const LibItem = ({ _id, removable, notifications, watched, ...props }) => { }, [_id, notifications]); const options = React.useMemo(() => { - const optionsList = [ + return [ { label: 'LIBRARY_PLAY', value: 'play' }, { label: 'LIBRARY_DETAILS', value: 'details' }, { label: 'LIBRARY_RESUME_DISMISS', value: 'dismiss' }, { label: watched ? 'CTX_MARK_UNWATCHED' : 'CTX_MARK_WATCHED', value: 'watched' }, { label: 'LIBRARY_REMOVE', value: 'remove' }, - ]; - return optionsList - .filter(({ value }) => { - switch (value) { - case 'play': - return props.deepLinks && typeof props.deepLinks.player === 'string'; - case 'details': - return props.deepLinks && (typeof props.deepLinks.metaDetailsVideos === 'string' || typeof props.deepLinks.metaDetailsStreams === 'string'); - case 'watched': - return props.deepLinks && (typeof props.deepLinks.metaDetailsVideos === 'string' || typeof props.deepLinks.metaDetailsStreams === 'string'); - case 'dismiss': - return typeof _id === 'string' && props.progress !== null && !isNaN(props.progress); - case 'remove': - return typeof _id === 'string' && removable; - } - }) - .map((option) => ({ - ...option, - label: t(option.label) - })); + ].filter(({ value }) => { + switch (value) { + case 'play': + return props.deepLinks && typeof props.deepLinks.player === 'string'; + case 'details': + return props.deepLinks && (typeof props.deepLinks.metaDetailsVideos === 'string' || typeof props.deepLinks.metaDetailsStreams === 'string'); + case 'watched': + return props.deepLinks && (typeof props.deepLinks.metaDetailsVideos === 'string' || typeof props.deepLinks.metaDetailsStreams === 'string'); + case 'dismiss': + return typeof _id === 'string' && props.progress !== null && !isNaN(props.progress); + case 'remove': + return typeof _id === 'string' && removable; + } + }).map((option) => ({ + ...option, + label: t(option.label) + })); }, [_id, removable, props.progress, props.deepLinks]); const optionOnSelect = React.useCallback((event) => { From 809ea6980319833e01d78e462933240616e3a539 Mon Sep 17 00:00:00 2001 From: kKaskak <117831817+kKaskak@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:57:25 +0200 Subject: [PATCH 7/7] refactor: watched dependencie added --- src/common/LibItem/LibItem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/LibItem/LibItem.js b/src/common/LibItem/LibItem.js index 88717c64c..1afd76bab 100644 --- a/src/common/LibItem/LibItem.js +++ b/src/common/LibItem/LibItem.js @@ -39,7 +39,7 @@ const LibItem = ({ _id, removable, notifications, watched, ...props }) => { ...option, label: t(option.label) })); - }, [_id, removable, props.progress, props.deepLinks]); + }, [_id, removable, props.progress, props.deepLinks, watched]); const optionOnSelect = React.useCallback((event) => { if (typeof props.optionOnSelect === 'function') {