mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-20 19:02:15 +00:00
map library item props in rust
This commit is contained in:
parent
5dbd62e14d
commit
c96b8b98af
2 changed files with 12 additions and 29 deletions
|
|
@ -12,7 +12,7 @@ const OPTIONS = [
|
|||
{ label: 'Remove', value: 'remove' },
|
||||
];
|
||||
|
||||
const LibItem = ({ id, removable, ...props }) => {
|
||||
const LibItem = ({ _id, removable, ...props }) => {
|
||||
const { core } = useServices();
|
||||
const options = React.useMemo(() => {
|
||||
return OPTIONS.filter(({ value }) => {
|
||||
|
|
@ -22,12 +22,12 @@ const LibItem = ({ id, removable, ...props }) => {
|
|||
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);
|
||||
return typeof _id === 'string' && props.progress !== null && !isNaN(props.progress);
|
||||
case 'remove':
|
||||
return typeof id === 'string' && removable;
|
||||
return typeof _id === 'string' && removable;
|
||||
}
|
||||
});
|
||||
}, [id, removable, props.progress, props.deepLinks]);
|
||||
}, [_id, removable, props.progress, props.deepLinks]);
|
||||
const optionOnSelect = React.useCallback((event) => {
|
||||
if (typeof props.optionOnSelect === 'function') {
|
||||
props.optionOnSelect(event);
|
||||
|
|
@ -54,12 +54,12 @@ const LibItem = ({ id, removable, ...props }) => {
|
|||
break;
|
||||
}
|
||||
case 'dismiss': {
|
||||
if (typeof id === 'string') {
|
||||
if (typeof _id === 'string') {
|
||||
core.transport.dispatch({
|
||||
action: 'Ctx',
|
||||
args: {
|
||||
action: 'RewindLibraryItem',
|
||||
args: id
|
||||
args: _id
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -67,12 +67,12 @@ const LibItem = ({ id, removable, ...props }) => {
|
|||
break;
|
||||
}
|
||||
case 'remove': {
|
||||
if (typeof id === 'string') {
|
||||
if (typeof _id === 'string') {
|
||||
core.transport.dispatch({
|
||||
action: 'Ctx',
|
||||
args: {
|
||||
action: 'RemoveFromLibrary',
|
||||
args: id
|
||||
args: _id
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ const LibItem = ({ id, removable, ...props }) => {
|
|||
}
|
||||
}
|
||||
}
|
||||
}, [id, props.deepLinks, props.optionOnSelect]);
|
||||
}, [_id, props.deepLinks, props.optionOnSelect]);
|
||||
return (
|
||||
<MetaItem
|
||||
{...props}
|
||||
|
|
@ -92,7 +92,7 @@ const LibItem = ({ id, removable, ...props }) => {
|
|||
};
|
||||
|
||||
LibItem.propTypes = {
|
||||
id: PropTypes.string,
|
||||
_id: PropTypes.string,
|
||||
removable: PropTypes.bool,
|
||||
progress: PropTypes.number,
|
||||
deepLinks: PropTypes.shape({
|
||||
|
|
|
|||
|
|
@ -4,29 +4,12 @@ const React = require('react');
|
|||
const { useServices } = require('stremio/services');
|
||||
const { useModelState } = require('stremio/common');
|
||||
|
||||
const map = (continueWatchingPreview) => ({
|
||||
...continueWatchingPreview,
|
||||
libraryItems: continueWatchingPreview.libraryItems.map((libItem) => ({
|
||||
id: libItem._id,
|
||||
type: libItem.type,
|
||||
name: libItem.name,
|
||||
poster: libItem.poster,
|
||||
posterShape: libItem.posterShape === 'landscape' ? 'square' : libItem.posterShape,
|
||||
progress: libItem.state.timeOffset > 0 && libItem.state.duration > 0 ?
|
||||
libItem.state.timeOffset / libItem.state.duration
|
||||
:
|
||||
null,
|
||||
playIcon: true,
|
||||
deepLinks: libItem.deepLinks
|
||||
}))
|
||||
});
|
||||
|
||||
const useContinueWatchingPreview = () => {
|
||||
const { core } = useServices();
|
||||
const init = React.useMemo(() => {
|
||||
return map(core.transport.getState('continue_watching_preview'));
|
||||
return core.transport.getState('continue_watching_preview');
|
||||
}, []);
|
||||
return useModelState({ model: 'continue_watching_preview', map, init });
|
||||
return useModelState({ model: 'continue_watching_preview', init });
|
||||
};
|
||||
|
||||
module.exports = useContinueWatchingPreview;
|
||||
|
|
|
|||
Loading…
Reference in a new issue