ueSort dropped

This commit is contained in:
NikolaBorislavovHristov 2019-12-08 14:37:54 +02:00
parent 5bcab12f4d
commit 466cbd0f23

View file

@ -1,37 +0,0 @@
const React = require('react');
const { useServices } = require('stremio/services');
const DEFAULT_SORT = 'recent';
const SORTS = [DEFAULT_SORT, 'year', 'a-z'];
const SORT_PROPS = new Map([
['recent', '_ctime'],
['a-z', 'name'],
['year', 'year']
]);
const useSort = (urlParams, queryParams) => {
const { core } = useServices();
const [sort, setSort] = React.useState([null, () => { }]);
React.useEffect(() => {
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) => {
if (a[sortProp] < b[sortProp]) return -1;
if (a[sortProp] > b[sortProp]) return 1;
return 0;
};
const selectInput = {
selected: [sort],
options: [{ label: 'Recent', value: 'recent' }, { label: 'A-Z', value: 'a-z' }, { label: 'Year', value: 'year' }],
onSelect: (event) => {
const nextQuery = new URLSearchParams({ sort: event.value });
const state = core.getState();
window.location.replace(`#/library/${state.library.selected.type_name !== null ? state.library.selected.type_name : ''}?${nextQuery}`);
}
};
setSort([selectInput, sortItems]);
}, [urlParams, queryParams]);
return sort;
};
module.exports = useSort;