mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-28 17:08:46 +00:00
get selected type from state
This commit is contained in:
parent
6be7f61866
commit
f0078427fa
1 changed files with 4 additions and 3 deletions
|
|
@ -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]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue