diff --git a/src/routes/Library/useSort.js b/src/routes/Library/useSort.js index 0dfe8980b..8909afa7b 100644 --- a/src/routes/Library/useSort.js +++ b/src/routes/Library/useSort.js @@ -1,6 +1,6 @@ const React = require('react'); +const { useServices } = require('stremio/services'); -const DEFAULT_TYPE = 'movie'; const DEFAULT_SORT = 'recent'; const SORTS = [DEFAULT_SORT, 'year', 'a-z']; const SORT_PROPS = new Map([ @@ -10,9 +10,9 @@ const SORT_PROPS = new Map([ ]); const useSort = (urlParams, queryParams) => { + const { core } = useServices(); const [sort, setSort] = React.useState([null, () => { }]); React.useEffect(() => { - const type = typeof type === 'string' && type.length > 0 ? urlParams.type : DEFAULT_TYPE; const sort = queryParams.has('sort') && SORTS.includes(queryParams.get('sort')) ? queryParams.get('sort') : DEFAULT_SORT; const sortProp = SORT_PROPS.get(sort); const sortItems = (a, b) => { @@ -25,7 +25,8 @@ const useSort = (urlParams, queryParams) => { options: [{ label: 'Recent', value: 'recent' }, { label: 'A-Z', value: 'a-z' }, { label: 'Year', value: 'year' }], onSelect: (event) => { const nextQuery = new URLSearchParams({ sort: event.value }); - window.location.replace(`#/library/${type}?${nextQuery}`); + const state = core.getState(); + window.location.replace(`#/library/${state.library.selected !== null ? state.library.selected : ''}?${nextQuery}`); } }; setSort([selectInput, sortItems]);