// Copyright (C) 2017-2023 Smart code 203358507 const React = require('react'); const PropTypes = require('prop-types'); const classnames = require('classnames'); const NotFound = require('stremio/routes/NotFound'); const { useProfile, useNotifications, routesRegexp, useOnScrollToBottom, withCoreSuspender } = require('stremio/common'); const { Button, DelayedRenderer, Chips, Image, MainNavBars, Multiselect, LibItem } = require('stremio/components'); const useLibrary = require('./useLibrary'); const useSelectableInputs = require('./useSelectableInputs'); const styles = require('./styles'); const SCROLL_TO_BOTTOM_TRESHOLD = 400; function withModel(Library) { const withModel = ({ urlParams, queryParams }) => { const model = React.useMemo(() => { return typeof urlParams.path === 'string' ? urlParams.path.match(routesRegexp.library.regexp) ? 'library' : urlParams.path.match(routesRegexp.continuewatching.regexp) ? 'continue_watching' : null : null; }, [urlParams.path]); if (model === null) { return ( ); } return ( ); }; withModel.displayName = 'withModel'; return withModel; } const Library = ({ model, urlParams, queryParams }) => { const profile = useProfile(); const notifications = useNotifications(); const [library, loadNextPage] = useLibrary(model, urlParams, queryParams); const [typeSelect, sortChips, hasNextPage] = useSelectableInputs(library); const scrollContainerRef = React.useRef(null); const onScrollToBottom = React.useCallback(() => { if (hasNextPage) { loadNextPage(); } }, [hasNextPage, loadNextPage]); const onScroll = useOnScrollToBottom(onScrollToBottom, SCROLL_TO_BOTTOM_TRESHOLD); React.useLayoutEffect(() => { if (profile.auth !== null && library.selected && library.selected.request.page === 1 && library.catalog.length !== 0 ) { scrollContainerRef.current.scrollTop = 0; } }, [profile.auth, library.selected]); return (
{ model === 'continue_watching' || profile.auth !== null ?
: null } { model === 'library' && profile.auth === null ?
{'
Library is only available for logged in users!
: library.selected === null ?
{'
{model === 'library' ? 'Library' : 'Continue Watching'} not loaded!
: library.catalog.length === 0 ?
{'
Empty {model === 'library' ? 'Library' : 'Continue Watching'}
:
{library.catalog.map((libItem, index) => ( ))}
}
); }; Library.propTypes = { model: PropTypes.oneOf(['library', 'continue_watching']), urlParams: PropTypes.shape({ type: PropTypes.string }), queryParams: PropTypes.instanceOf(URLSearchParams) }; const LibraryFallback = ({ model }) => ( ); LibraryFallback.propTypes = Library.propTypes; module.exports = withModel(withCoreSuspender(Library, LibraryFallback));