mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-21 03:22:11 +00:00
feature: mark libItem as watched / unwatched
This commit is contained in:
parent
18236ae752
commit
23dfeb263b
2 changed files with 34 additions and 8 deletions
|
|
@ -6,19 +6,23 @@ const PropTypes = require('prop-types');
|
||||||
const MetaItem = require('stremio/common/MetaItem');
|
const MetaItem = require('stremio/common/MetaItem');
|
||||||
const { t } = require('i18next');
|
const { t } = require('i18next');
|
||||||
|
|
||||||
const OPTIONS = [
|
const LibItem = ({ _id, removable, notifications, watched, ...props }) => {
|
||||||
{ label: 'LIBRARY_PLAY', value: 'play' },
|
|
||||||
{ label: 'LIBRARY_DETAILS', value: 'details' },
|
const OPTIONS = [
|
||||||
{ label: 'LIBRARY_RESUME_DISMISS', value: 'dismiss' },
|
{ label: 'LIBRARY_PLAY', value: 'play' },
|
||||||
{ label: 'LIBRARY_REMOVE', value: 'remove' },
|
{ 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 { core } = useServices();
|
||||||
|
|
||||||
const newVideos = React.useMemo(() => {
|
const newVideos = React.useMemo(() => {
|
||||||
const count = notifications.items?.[_id]?.length ?? 0;
|
const count = notifications.items?.[_id]?.length ?? 0;
|
||||||
return Math.min(Math.max(count, 0), 99);
|
return Math.min(Math.max(count, 0), 99);
|
||||||
}, [_id, notifications]);
|
}, [_id, notifications]);
|
||||||
|
|
||||||
const options = React.useMemo(() => {
|
const options = React.useMemo(() => {
|
||||||
return OPTIONS
|
return OPTIONS
|
||||||
.filter(({ value }) => {
|
.filter(({ value }) => {
|
||||||
|
|
@ -27,6 +31,8 @@ const LibItem = ({ _id, removable, notifications, ...props }) => {
|
||||||
return props.deepLinks && typeof props.deepLinks.player === 'string';
|
return props.deepLinks && typeof props.deepLinks.player === 'string';
|
||||||
case 'details':
|
case 'details':
|
||||||
return props.deepLinks && (typeof props.deepLinks.metaDetailsVideos === 'string' || typeof props.deepLinks.metaDetailsStreams === 'string');
|
return props.deepLinks && (typeof props.deepLinks.metaDetailsVideos === 'string' || typeof props.deepLinks.metaDetailsStreams === 'string');
|
||||||
|
case 'watched':
|
||||||
|
return typeof _id === 'string' && watched !== null;
|
||||||
case 'dismiss':
|
case 'dismiss':
|
||||||
return typeof _id === 'string' && props.progress !== null && !isNaN(props.progress);
|
return typeof _id === 'string' && props.progress !== null && !isNaN(props.progress);
|
||||||
case 'remove':
|
case 'remove':
|
||||||
|
|
@ -38,6 +44,7 @@ const LibItem = ({ _id, removable, notifications, ...props }) => {
|
||||||
label: t(option.label)
|
label: t(option.label)
|
||||||
}));
|
}));
|
||||||
}, [_id, removable, props.progress, props.deepLinks]);
|
}, [_id, removable, props.progress, props.deepLinks]);
|
||||||
|
|
||||||
const optionOnSelect = React.useCallback((event) => {
|
const optionOnSelect = React.useCallback((event) => {
|
||||||
if (typeof props.optionOnSelect === 'function') {
|
if (typeof props.optionOnSelect === 'function') {
|
||||||
props.optionOnSelect(event);
|
props.optionOnSelect(event);
|
||||||
|
|
@ -83,6 +90,22 @@ const LibItem = ({ _id, removable, notifications, ...props }) => {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'watched': {
|
||||||
|
if (typeof _id === 'string') {
|
||||||
|
core.transport.dispatch({
|
||||||
|
action: 'Ctx',
|
||||||
|
args: {
|
||||||
|
action: 'LibraryItemMarkAsWatched',
|
||||||
|
args: {
|
||||||
|
id: _id,
|
||||||
|
is_watched: !watched
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'remove': {
|
case 'remove': {
|
||||||
if (typeof _id === 'string') {
|
if (typeof _id === 'string') {
|
||||||
core.transport.dispatch({
|
core.transport.dispatch({
|
||||||
|
|
@ -99,9 +122,11 @@ const LibItem = ({ _id, removable, notifications, ...props }) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [_id, props.deepLinks, props.optionOnSelect]);
|
}, [_id, props.deepLinks, props.optionOnSelect]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MetaItem
|
<MetaItem
|
||||||
{...props}
|
{...props}
|
||||||
|
watched={watched}
|
||||||
newVideos={newVideos}
|
newVideos={newVideos}
|
||||||
options={options}
|
options={options}
|
||||||
optionOnSelect={optionOnSelect}
|
optionOnSelect={optionOnSelect}
|
||||||
|
|
@ -114,6 +139,7 @@ LibItem.propTypes = {
|
||||||
removable: PropTypes.bool,
|
removable: PropTypes.bool,
|
||||||
progress: PropTypes.number,
|
progress: PropTypes.number,
|
||||||
notifications: PropTypes.object,
|
notifications: PropTypes.object,
|
||||||
|
watched: PropTypes.bool,
|
||||||
deepLinks: PropTypes.shape({
|
deepLinks: PropTypes.shape({
|
||||||
metaDetailsVideos: PropTypes.string,
|
metaDetailsVideos: PropTypes.string,
|
||||||
metaDetailsStreams: PropTypes.string,
|
metaDetailsStreams: PropTypes.string,
|
||||||
|
|
|
||||||
|
|
@ -351,7 +351,7 @@
|
||||||
width: auto;
|
width: auto;
|
||||||
|
|
||||||
.multiselect-menu-container {
|
.multiselect-menu-container {
|
||||||
min-width: 8rem;
|
min-width: 9rem;
|
||||||
max-width: 14rem;
|
max-width: 14rem;
|
||||||
|
|
||||||
.multiselect-option-container {
|
.multiselect-option-container {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue