continue_watching flag removed in library

This commit is contained in:
nklhrstv 2020-03-27 23:28:18 +02:00
parent 2978b38e8a
commit b3c826a16e
2 changed files with 11 additions and 48 deletions

View file

@ -1,8 +1,6 @@
const React = require('react');
const { useModelState } = require('stremio/common');
const DEFAULT_SORT = 'lastwatched';
const initLibraryState = () => ({
selected: null,
type_names: [],
@ -28,44 +26,22 @@ const mapLibraryState = (library) => {
return { selected, type_names, lib_items };
};
const onNewLibraryState = (library) => {
if (library.selected === null) {
return {
action: 'Load',
args: {
model: 'LibraryWithFilters',
args: {
type_name: null,
sort: DEFAULT_SORT,
continue_watching: false
}
}
};
} else {
return null;
}
};
const useLibrary = (urlParams, queryParams) => {
const loadLibraryAction = React.useMemo(() => {
return {
action: 'Load',
const loadLibraryAction = React.useMemo(() => ({
action: 'Load',
args: {
model: 'LibraryWithFilters',
args: {
model: 'LibraryWithFilters',
args: {
type_name: typeof urlParams.type === 'string' ? urlParams.type : null,
sort: queryParams.has('sort') ? queryParams.get('sort') : DEFAULT_SORT,
continue_watching: queryParams.get('cw') === '1'
}
type_name: typeof urlParams.type === 'string' ? urlParams.type : null,
sort: queryParams.has('sort') ? queryParams.get('sort') : 'lastwatched'
}
};
}, [urlParams, queryParams]);
}
}), [urlParams, queryParams]);
return useModelState({
model: 'library',
action: loadLibraryAction,
map: mapLibraryState,
init: initLibraryState,
onNewState: onNewLibraryState
init: initLibraryState
});
};

View file

@ -17,15 +17,7 @@ const mapSelectableInputs = (library) => {
.concat(library.type_names.map((type) => ({ label: type, value: JSON.stringify(type) }))),
onSelect: (event) => {
const type = JSON.parse(event.value);
const queryParams = new URLSearchParams(
library.selected !== null ?
[
['sort', library.selected.sort],
['cw', library.selected.continue_watching ? '1' : '0']
]
:
[]
);
const queryParams = new URLSearchParams(library.selected !== null ? [['sort', library.selected.sort]] : []);
window.location.replace(`#/library${type !== null ? `/${encodeURIComponent(type)}` : ''}?${queryParams.toString()}`);
}
};
@ -38,12 +30,7 @@ const mapSelectableInputs = (library) => {
options: SORT_OPTIONS,
onSelect: (event) => {
const type = library.selected !== null ? library.selected.type_name : null;
const queryParams = new URLSearchParams(
[
['sort', event.value],
['cw', library.selected !== null && library.selected.continue_watching ? '1' : '0']
]
);
const queryParams = new URLSearchParams([['sort', event.value]]);
window.location.replace(`#/library${type !== null ? `/${encodeURIComponent(type)}` : ''}?${queryParams.toString()}`);
}
};