stremio-web/src/routes/Library/useLibrary.js
2022-07-06 17:16:33 +03:00

23 lines
793 B
JavaScript

// Copyright (C) 2017-2022 Smart code 203358507
const React = require('react');
const { useModelState } = require('stremio/common');
const useLibrary = (model, urlParams, queryParams) => {
const action = React.useMemo(() => ({
action: 'Load',
args: {
model: 'LibraryWithFilters',
args: {
request: {
type: typeof urlParams.type === 'string' ? urlParams.type : null,
sort: queryParams.has('sort') ? queryParams.get('sort') : undefined,
page: queryParams.has('page') ? parseInt(queryParams.get('page'), 10) : undefined
}
}
}
}), [urlParams, queryParams]);
return useModelState({ model, action });
};
module.exports = useLibrary;