mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-21 03:22:11 +00:00
fix(Library): parse correct url and query params and model type
This commit is contained in:
parent
95a3965f11
commit
d0891adddf
1 changed files with 17 additions and 26 deletions
|
|
@ -1,10 +1,12 @@
|
||||||
// Copyright (C) 2017-2023 Smart code 203358507
|
// Copyright (C) 2017-2023 Smart code 203358507
|
||||||
|
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
|
const { useLocation, useParams } = require('react-router');
|
||||||
|
const { useSearchParams } = require('react-router-dom');
|
||||||
const PropTypes = require('prop-types');
|
const PropTypes = require('prop-types');
|
||||||
const classnames = require('classnames');
|
const classnames = require('classnames');
|
||||||
const NotFound = require('stremio/routes/NotFound');
|
const NotFound = require('stremio/routes/NotFound');
|
||||||
const { useProfile, useNotifications, routesRegexp, useOnScrollToBottom, withCoreSuspender } = require('stremio/common');
|
const { useProfile, useNotifications, useOnScrollToBottom, withCoreSuspender } = require('stremio/common');
|
||||||
const { DelayedRenderer, Chips, Image, MainNavBars, Multiselect, LibItem } = require('stremio/components');
|
const { DelayedRenderer, Chips, Image, MainNavBars, Multiselect, LibItem } = require('stremio/components');
|
||||||
const { default: Placeholder } = require('./Placeholder');
|
const { default: Placeholder } = require('./Placeholder');
|
||||||
const useLibrary = require('./useLibrary');
|
const useLibrary = require('./useLibrary');
|
||||||
|
|
@ -13,40 +15,33 @@ const styles = require('./styles');
|
||||||
|
|
||||||
const SCROLL_TO_BOTTOM_TRESHOLD = 400;
|
const SCROLL_TO_BOTTOM_TRESHOLD = 400;
|
||||||
|
|
||||||
function withModel(Library) {
|
function withModel(Library, useLocation) {
|
||||||
const withModel = ({ urlParams, queryParams }) => {
|
const withModel = () => {
|
||||||
|
const location = useLocation();
|
||||||
const model = React.useMemo(() => {
|
const model = React.useMemo(() => {
|
||||||
return typeof urlParams.path === 'string' ?
|
return typeof location.pathname === 'string' ?
|
||||||
urlParams.path.match(routesRegexp.library.regexp) ?
|
location.pathname.match('/library') ?
|
||||||
'library'
|
'library'
|
||||||
:
|
:
|
||||||
urlParams.path.match(routesRegexp.continuewatching.regexp) ?
|
location.pathname.match('/continuewatching') ?
|
||||||
'continue_watching'
|
'continue_watching'
|
||||||
:
|
:
|
||||||
null
|
null
|
||||||
:
|
:
|
||||||
null;
|
null;
|
||||||
}, [urlParams.path]);
|
}, [location?.pathname]);
|
||||||
if (model === null) {
|
|
||||||
return (
|
|
||||||
<NotFound />
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
if (model === null) return <NotFound />;
|
||||||
<Library
|
|
||||||
key={model}
|
return <Library model={model} />;
|
||||||
model={model}
|
|
||||||
urlParams={urlParams}
|
|
||||||
queryParams={queryParams}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
withModel.displayName = 'withModel';
|
withModel.displayName = 'withModel';
|
||||||
return withModel;
|
return withModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Library = ({ model, urlParams, queryParams }) => {
|
const Library = ({ model }) => {
|
||||||
|
const urlParams = useParams();
|
||||||
|
const [queryParams] = useSearchParams();
|
||||||
const profile = useProfile();
|
const profile = useProfile();
|
||||||
const notifications = useNotifications();
|
const notifications = useNotifications();
|
||||||
const [library, loadNextPage] = useLibrary(model, urlParams, queryParams);
|
const [library, loadNextPage] = useLibrary(model, urlParams, queryParams);
|
||||||
|
|
@ -118,10 +113,6 @@ const Library = ({ model, urlParams, queryParams }) => {
|
||||||
|
|
||||||
Library.propTypes = {
|
Library.propTypes = {
|
||||||
model: PropTypes.oneOf(['library', 'continue_watching']),
|
model: PropTypes.oneOf(['library', 'continue_watching']),
|
||||||
urlParams: PropTypes.shape({
|
|
||||||
type: PropTypes.string
|
|
||||||
}),
|
|
||||||
queryParams: PropTypes.instanceOf(URLSearchParams)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const LibraryFallback = ({ model }) => (
|
const LibraryFallback = ({ model }) => (
|
||||||
|
|
@ -130,4 +121,4 @@ const LibraryFallback = ({ model }) => (
|
||||||
|
|
||||||
LibraryFallback.propTypes = Library.propTypes;
|
LibraryFallback.propTypes = Library.propTypes;
|
||||||
|
|
||||||
module.exports = withModel(withCoreSuspender(Library, LibraryFallback));
|
module.exports = withModel(withCoreSuspender(Library, LibraryFallback), useLocation);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue