diff --git a/src/common/routesRegexp.js b/src/common/routesRegexp.js
index b5bf69db4..569f926e5 100644
--- a/src/common/routesRegexp.js
+++ b/src/common/routesRegexp.js
@@ -12,7 +12,7 @@ const routesRegexp = {
urlParamsNames: ['transportUrl', 'type', 'catalogId']
},
library: {
- regexp: /^\/library(?:\/([^/]*)\/([^/]*))?$/,
+ regexp: /^\/library(?:\/([^/]*))?(?:\/([^/]*))?$/,
urlParamsNames: ['type', 'sort']
},
search: {
diff --git a/src/routes/Intro/Intro.js b/src/routes/Intro/Intro.js
index 168eb2e15..aa356cd27 100644
--- a/src/routes/Intro/Intro.js
+++ b/src/routes/Intro/Intro.js
@@ -16,13 +16,13 @@ const LOGIN_FORM = 'login';
const Intro = ({ queryParams }) => {
const { core } = useServices();
const routeFocused = useRouteFocused();
- const emailRef = React.useRef();
- const passwordRef = React.useRef();
- const confirmPasswordRef = React.useRef();
- const termsRef = React.useRef();
- const privacyPolicyRef = React.useRef();
- const marketingRef = React.useRef();
- const errorRef = React.useRef();
+ const emailRef = React.useRef(null);
+ const passwordRef = React.useRef(null);
+ const confirmPasswordRef = React.useRef(null);
+ const termsRef = React.useRef(null);
+ const privacyPolicyRef = React.useRef(null);
+ const marketingRef = React.useRef(null);
+ const errorRef = React.useRef(null);
const [passwordRestModalOpen, openPasswordRestModal, closePasswordResetModal] = useBinaryState(false);
const [loaderModalOpen, openLoaderModal, closeLoaderModal] = useBinaryState(false);
const [state, dispatch] = React.useReducer(
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)}`);
}
}
};
diff --git a/src/services/Core/Core.js b/src/services/Core/Core.js
index fc27e01cf..03773ed8b 100644
--- a/src/services/Core/Core.js
+++ b/src/services/Core/Core.js
@@ -58,7 +58,7 @@ function Core() {
events.off(name, listener);
}
function dispatch(action, model) {
- if (!active) {
+ if (!active || typeof action === 'undefined') {
return false;
}