diff --git a/src/common/LibItem/LibItem.js b/src/common/LibItem/LibItem.js index d2858790d..1afd76bab 100644 --- a/src/common/LibItem/LibItem.js +++ b/src/common/LibItem/LibItem.js @@ -6,38 +6,41 @@ 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 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 }) => { - 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 '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]); + 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' }, + ].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, watched]); + const optionOnSelect = React.useCallback((event) => { if (typeof props.optionOnSelect === 'function') { props.optionOnSelect(event); @@ -63,6 +66,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 'dismiss': { if (typeof _id === 'string') { core.transport.dispatch({ @@ -99,9 +118,11 @@ const LibItem = ({ _id, removable, notifications, ...props }) => { } } }, [_id, props.deepLinks, props.optionOnSelect]); + return (