mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-12 23:40:26 +00:00
feat(useSelectableInputs): use navigate instead window location
This commit is contained in:
parent
3c012fccca
commit
ba652b8e5c
3 changed files with 19 additions and 13 deletions
|
|
@ -1,9 +1,10 @@
|
|||
// Copyright (C) 2017-2023 Smart code 203358507
|
||||
|
||||
const React = require('react');
|
||||
const { useNavigate } = require('react-router');
|
||||
const { useTranslate } = require('stremio/common');
|
||||
|
||||
const mapSelectableInputs = (installedAddons, remoteAddons, t) => {
|
||||
const mapSelectableInputs = (installedAddons, remoteAddons, t, navigate) => {
|
||||
const catalogSelect = {
|
||||
title: t.string('SELECT_CATALOG'),
|
||||
options: remoteAddons.selectable.catalogs
|
||||
|
|
@ -26,7 +27,7 @@ const mapSelectableInputs = (installedAddons, remoteAddons, t) => {
|
|||
:
|
||||
null,
|
||||
onSelect: (event) => {
|
||||
window.location = event.value;
|
||||
navigate(event.value.replace('#', ''));
|
||||
}
|
||||
};
|
||||
const typeSelect = {
|
||||
|
|
@ -62,7 +63,7 @@ const mapSelectableInputs = (installedAddons, remoteAddons, t) => {
|
|||
typeSelect.title;
|
||||
},
|
||||
onSelect: (event) => {
|
||||
window.location = event.value;
|
||||
navigate(event.value.replace('#', ''));
|
||||
}
|
||||
};
|
||||
return [catalogSelect, typeSelect];
|
||||
|
|
@ -70,8 +71,9 @@ const mapSelectableInputs = (installedAddons, remoteAddons, t) => {
|
|||
|
||||
const useSelectableInputs = (installedAddons, remoteAddons) => {
|
||||
const t = useTranslate();
|
||||
const navigate = useNavigate();
|
||||
const selectableInputs = React.useMemo(() => {
|
||||
return mapSelectableInputs(installedAddons, remoteAddons, t);
|
||||
return mapSelectableInputs(installedAddons, remoteAddons, t, navigate);
|
||||
}, [installedAddons, remoteAddons]);
|
||||
return selectableInputs;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
// Copyright (C) 2017-2023 Smart code 203358507
|
||||
|
||||
const React = require('react');
|
||||
const { useNavigate } = require('react-router');
|
||||
const { useTranslate } = require('stremio/common');
|
||||
|
||||
const mapSelectableInputs = (discover, t) => {
|
||||
const mapSelectableInputs = (discover, t, navigate) => {
|
||||
const typeSelect = {
|
||||
title: t.string('SELECT_TYPE'),
|
||||
options: discover.selectable.types
|
||||
|
|
@ -19,7 +20,7 @@ const mapSelectableInputs = (discover, t) => {
|
|||
:
|
||||
null,
|
||||
onSelect: (event) => {
|
||||
window.location = event.value;
|
||||
navigate(event.value.replace('#', ''));
|
||||
}
|
||||
};
|
||||
const catalogSelect = {
|
||||
|
|
@ -42,7 +43,7 @@ const mapSelectableInputs = (discover, t) => {
|
|||
:
|
||||
null,
|
||||
onSelect: (event) => {
|
||||
window.location = event.value;
|
||||
navigate(event.value.replace('#', ''));
|
||||
}
|
||||
};
|
||||
const extraSelects = discover.selectable.extra.map(({ name, isRequired, options }) => ({
|
||||
|
|
@ -67,7 +68,7 @@ const mapSelectableInputs = (discover, t) => {
|
|||
null,
|
||||
onSelect: (event) => {
|
||||
const { href } = JSON.parse(event.value);
|
||||
window.location = href;
|
||||
navigate(href.replace('#', ''));
|
||||
}
|
||||
}));
|
||||
return [[typeSelect, catalogSelect, ...extraSelects], discover.selectable.nextPage];
|
||||
|
|
@ -75,8 +76,9 @@ const mapSelectableInputs = (discover, t) => {
|
|||
|
||||
const useSelectableInputs = (discover) => {
|
||||
const t = useTranslate();
|
||||
const navigate = useNavigate();
|
||||
const selectableInputs = React.useMemo(() => {
|
||||
return mapSelectableInputs(discover, t);
|
||||
return mapSelectableInputs(discover, t, navigate);
|
||||
}, [discover.selected, discover.selectable]);
|
||||
return selectableInputs;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
// Copyright (C) 2017-2023 Smart code 203358507
|
||||
|
||||
const React = require('react');
|
||||
const { useNavigate } = require('react-router');
|
||||
const { useTranslate } = require('stremio/common');
|
||||
|
||||
const mapSelectableInputs = (library, t) => {
|
||||
const mapSelectableInputs = (library, t, navigate) => {
|
||||
const selectedType = library.selectable.types
|
||||
.filter(({ selected }) => selected).map(({ deepLinks }) => deepLinks.library);
|
||||
const typeSelect = {
|
||||
|
|
@ -17,7 +18,7 @@ const mapSelectableInputs = (library, t) => {
|
|||
? selectedType
|
||||
: [library.selectable.types[0]].map(({ deepLinks }) => deepLinks.library),
|
||||
onSelect: (event) => {
|
||||
window.location = event.value;
|
||||
navigate(event.value.replace('#', ''));
|
||||
}
|
||||
};
|
||||
const sortChips = {
|
||||
|
|
@ -30,7 +31,7 @@ const mapSelectableInputs = (library, t) => {
|
|||
.filter(({ selected }) => selected)
|
||||
.map(({ deepLinks }) => deepLinks.library),
|
||||
onSelect: (value) => {
|
||||
window.location = value;
|
||||
navigate(value.replace('#', ''));
|
||||
}
|
||||
};
|
||||
return [typeSelect, sortChips, library.selectable.nextPage];
|
||||
|
|
@ -38,8 +39,9 @@ const mapSelectableInputs = (library, t) => {
|
|||
|
||||
const useSelectableInputs = (library) => {
|
||||
const t = useTranslate();
|
||||
const navigate = useNavigate();
|
||||
const selectableInputs = React.useMemo(() => {
|
||||
return mapSelectableInputs(library, t);
|
||||
return mapSelectableInputs(library, t, navigate);
|
||||
}, [library]);
|
||||
return selectableInputs;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue