diff --git a/src/routes/Library/Library.js b/src/routes/Library/Library.js index 8667c67ae..0503689c2 100644 --- a/src/routes/Library/Library.js +++ b/src/routes/Library/Library.js @@ -1,7 +1,7 @@ const React = require('react'); const PropTypes = require('prop-types'); const classnames = require('classnames'); -const { Button, Multiselect, MainNavBar, MetaItem } = require('stremio/common'); +const { Button, Multiselect, MainNavBar, MetaItem, useProfile } = require('stremio/common'); const useLibrary = require('./useLibrary'); const useSelectableInputs = require('./useSelectableInputs'); const useItemOptions = require('./useItemOptions'); @@ -9,6 +9,7 @@ const styles = require('./styles'); const Library = ({ urlParams }) => { const library = useLibrary(urlParams); + const profile = useProfile(); const [typeSelect, sortPropSelect] = useSelectableInputs(library); const [options, optionOnSelect] = useItemOptions(); return ( @@ -16,7 +17,7 @@ const Library = ({ urlParams }) => {
{ - library.library_state.type === 'Ready' && library.library_state.content.uid !== null && library.type_names.length > 0 ? + profile.auth !== null && library.type_names.length > 0 ?
@@ -25,7 +26,7 @@ const Library = ({ urlParams }) => { null } { - library.library_state.type === 'Ready' && library.library_state.content.uid === null ? + profile.auth === null ?
Library is only availavle for logged in users
: - library.library_state.type !== 'Ready' ? + library.type_names.length === 0 ?
-
Loading
+
Empty library
: - library.type_names.length === 0 ? + library.selected === null ?
-
Empty library
+
Please select a type
: - library.selected === null ? + library.lib_items.length === 0 ?
-
Please select a type
+
There are no items for the selected type
: - library.lib_items.length === 0 ? -
-
There are no items for the selected type
-
- : -
- {library.lib_items.map(({ id, videoId, ...libItem }, index) => ( - - ))} -
+
+ {library.lib_items.map(({ id, videoId, ...libItem }, index) => ( + + ))} +
}
diff --git a/src/routes/Library/useLibrary.js b/src/routes/Library/useLibrary.js index 69c63f56e..b5549766f 100644 --- a/src/routes/Library/useLibrary.js +++ b/src/routes/Library/useLibrary.js @@ -3,16 +3,12 @@ const { useServices } = require('stremio/services'); const { useModelState } = require('stremio/common'); const initLibraryState = () => ({ - library_state: { - type: 'NotLoaded' - }, selected: null, type_names: [], lib_items: [] }); const mapLibraryState = (library) => { - const library_state = library.library_state; const selected = library.selected; const type_names = library.type_names; const lib_items = library.lib_items.map((lib_item) => ({ @@ -28,7 +24,7 @@ const mapLibraryState = (library) => { videoId: lib_item.state.video_id, href: `#/metadetails/${encodeURIComponent(lib_item.type)}/${encodeURIComponent(lib_item._id)}${lib_item.state.video_id !== null ? `/${encodeURIComponent(lib_item.state.video_id)}` : ''}` })); - return { library_state, selected, type_names, lib_items }; + return { selected, type_names, lib_items }; }; const onNewLibraryState = (library) => { @@ -36,10 +32,9 @@ const onNewLibraryState = (library) => { return { action: 'Load', args: { - load: 'LibraryFiltered', + model: 'LibraryWithFilters', args: { - type_name: library.type_names[0], - sort_prop: null + type_name: library.type_names[0] } } }; @@ -53,23 +48,32 @@ const useLibrary = (urlParams) => { return { action: 'Load', args: { - load: 'LibraryFiltered', + model: 'LibraryWithFilters', args: { type_name: urlParams.type, sort_prop: urlParams.sort } } }; + } else if (typeof urlParams.type === 'string') { + return { + action: 'Load', + args: { + model: 'LibraryWithFilters', + args: { + type_name: urlParams.type + } + } + }; } else { const library = core.getState('library'); if (library.type_names.length > 0) { return { action: 'Load', args: { - load: 'LibraryFiltered', + model: 'LibraryWithFilters', args: { - type_name: library.type_names[0], - sort_prop: null + type_name: library.type_names[0] } } }; diff --git a/src/routes/Library/useSelectableInputs.js b/src/routes/Library/useSelectableInputs.js index 645db1457..9fcb33a3d 100644 --- a/src/routes/Library/useSelectableInputs.js +++ b/src/routes/Library/useSelectableInputs.js @@ -1,7 +1,7 @@ const React = require('react'); const SORT_PROP_OPTIONS = [ - { label: 'Recent', value: '_ctime' }, + { label: 'Recent', value: 'ctime' }, { label: 'A-Z', value: 'name' }, { label: 'Year', value: 'year' }, ]; @@ -16,7 +16,7 @@ const mapSelectableInputs = (library) => { options: library.type_names .map((type) => ({ label: type, value: type })), onSelect: (event) => { - window.location.replace(`#/library/${encodeURIComponent(event.value)}/${encodeURIComponent(library.selected.sort_prop)}`); + window.location.replace(`#/library/${encodeURIComponent(event.value)}`); } }; const sortPropSelect = { @@ -29,6 +29,8 @@ const mapSelectableInputs = (library) => { onSelect: (event) => { if (library.selected !== null) { window.location.replace(`#/library/${encodeURIComponent(library.selected.type_name)}/${encodeURIComponent(event.value)}`); + } else if (library.type_names.length > 0) { + window.location.replace(`#/library/${encodeURIComponent(library.type_names[0])}/${encodeURIComponent(event.value)}`); } } };