From 34cf2280a4542caabd2b6846ace843de8c48e1ab Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Thu, 28 Nov 2019 11:51:47 +0200 Subject: [PATCH 01/15] search linked with stremio-core --- src/routes/Search/Search.js | 39 +++++++++++++---- src/routes/Search/styles.less | 78 ++++++++++++++++++++++++++++++++-- src/routes/Search/useSearch.js | 55 ++++++++++++------------ 3 files changed, 133 insertions(+), 39 deletions(-) diff --git a/src/routes/Search/Search.js b/src/routes/Search/Search.js index b97096a5b..ff5a32dd6 100644 --- a/src/routes/Search/Search.js +++ b/src/routes/Search/Search.js @@ -4,18 +4,41 @@ const useSearch = require('./useSearch'); const styles = require('./styles'); const Search = ({ queryParams }) => { - const groups = useSearch(queryParams.get('q')); + const groups = useSearch(queryParams); return (
- {groups.map((group, index) => ( - - ))} + {groups.map(({ req, content }, index) => { + switch (content.type) { + case 'Ready': + return ( + + ); + case 'Err': + return ( + + ); + case 'Loading': + return ( + + ); + } + })}
); diff --git a/src/routes/Search/styles.less b/src/routes/Search/styles.less index 40e01a4d2..338672b2e 100644 --- a/src/routes/Search/styles.less +++ b/src/routes/Search/styles.less @@ -1,7 +1,13 @@ +@import (reference) '~stremio/common/screen-sizes.less'; + :import('~stremio/common/MetaRow/styles.less') { meta-item: meta-item; } +:import('~stremio/common/MetaRow/MetaRowPlaceholder/styles.less') { + meta-item-placeholder: meta-item; +} + .search-container { display: flex; flex-direction: column; @@ -19,7 +25,7 @@ align-self: stretch; overflow-y: auto; - .search-row { + .search-row, .search-row-placeholder { margin: 4rem 2rem; &:first-child { @@ -29,10 +35,74 @@ &:last-child { margin-bottom: 2rem; } + } + } +} - .meta-item { - &:nth-child(n+6) { - display: none; +@media only screen and (min-width: @large) { + .board-container { + .board-content { + .board-row, .board-row-placeholder { + .meta-item, .meta-item-placeholder { + &:nth-child(n+9) { + display: none; + } + } + } + } + } +} + +@media only screen and (max-width: @large) { + .search-container { + .search-content { + .search-row, .search-row-placeholder { + .meta-item, .meta-item-placeholder { + &:nth-child(n+8) { + display: none; + } + } + } + } + } +} + +@media only screen and (max-width: @medium) { + .search-container { + .search-content { + .search-row, .search-row-placeholder { + .meta-item, .meta-item-placeholder { + &:nth-child(n+7) { + display: none; + } + } + } + } + } +} + +@media only screen and (max-width: @small) { + .search-container { + .search-content { + .search-row, .search-row-placeholder { + .meta-item, .meta-item-placeholder { + &:nth-child(n+6) { + display: none; + } + } + } + } + } +} + +@media only screen and (max-width: @xsmall) { + .search-container { + .search-content { + .search-row, .search-row-placeholder { + .meta-item, .meta-item-placeholder { + &:nth-child(n+5) { + display: none; + } } } } diff --git a/src/routes/Search/useSearch.js b/src/routes/Search/useSearch.js index 68289c202..7cac22bf3 100644 --- a/src/routes/Search/useSearch.js +++ b/src/routes/Search/useSearch.js @@ -1,32 +1,33 @@ const React = require('react'); +const { useServices } = require('stremio/services'); -const useSearch = (query) => { - const items = React.useMemo(() => { - return [ - { - title: 'demo addon', - items: [ - { - id: '1', - type: 'movie', - name: 'Stremio demo item movie 1', - poster: '/images/intro_background.jpg', - logo: '/images/default_avatar.png', - posterShape: 'poster' - }, - { - id: '2', - type: 'movie', - name: 'Stremio demo item movie 2', - poster: '/images/intro_background.jpg', - logo: '/images/default_avatar.png', - posterShape: 'poster' - }, - ] - } - ]; - }, [query]); - return items; +const useSearch = (queryParams) => { + const { core } = useServices(); + const [search, setSearch] = React.useState([]); + React.useEffect(() => { + const onNewState = () => { + const state = core.getState(); + setSearch(state.search.groups); + }; + core.on('NewModel', onNewState); + if (queryParams.has('q')) { + core.dispatch({ + action: 'Load', + args: { + load: 'CatalogGrouped', + args: { + extra: [ + ['search', queryParams.get('q')] + ] + } + } + }); + } + return () => { + core.off('NewModel', onNewState); + }; + }, [queryParams]); + return search; }; module.exports = useSearch; From 609772a9326e7ec8b37a504cdbb55d5875242daa Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Thu, 28 Nov 2019 14:50:46 +0200 Subject: [PATCH 02/15] search adapted to stremio-core changes --- src/routes/Search/Search.js | 14 +++++++------- src/routes/Search/useSearch.js | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/routes/Search/Search.js b/src/routes/Search/Search.js index ff5a32dd6..45696f8d4 100644 --- a/src/routes/Search/Search.js +++ b/src/routes/Search/Search.js @@ -9,32 +9,32 @@ const Search = ({ queryParams }) => {
- {groups.map(({ req, content }, index) => { + {groups.map(({ request, content }, index) => { switch (content.type) { case 'Ready': return ( ); case 'Err': return ( ); case 'Loading': return ( ); } diff --git a/src/routes/Search/useSearch.js b/src/routes/Search/useSearch.js index 7cac22bf3..5271ec2b6 100644 --- a/src/routes/Search/useSearch.js +++ b/src/routes/Search/useSearch.js @@ -7,14 +7,14 @@ const useSearch = (queryParams) => { React.useEffect(() => { const onNewState = () => { const state = core.getState(); - setSearch(state.search.groups); + setSearch(state.search.items_groups); }; core.on('NewModel', onNewState); if (queryParams.has('q')) { core.dispatch({ action: 'Load', args: { - load: 'CatalogGrouped', + load: 'CatalogsGrouped', args: { extra: [ ['search', queryParams.get('q')] From eb9bbeab0b4e04757496b14db58330ce4985cab3 Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Thu, 28 Nov 2019 17:06:13 +0200 Subject: [PATCH 03/15] board adapted to stremio-core changes --- src/routes/Board/Board.js | 14 +++++++------- src/routes/Board/useCatalogs.js | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/routes/Board/Board.js b/src/routes/Board/Board.js index 1b626f6ca..980b47f11 100644 --- a/src/routes/Board/Board.js +++ b/src/routes/Board/Board.js @@ -20,32 +20,32 @@ const Board = () => {
- {catalogs.map(({ req, content }, index) => { + {catalogs.map(({ request, content }, index) => { switch (content.type) { case 'Ready': return ( ); case 'Message': return ( ); case 'Loading': return ( ); } diff --git a/src/routes/Board/useCatalogs.js b/src/routes/Board/useCatalogs.js index d2470ff9e..ce865f2d5 100644 --- a/src/routes/Board/useCatalogs.js +++ b/src/routes/Board/useCatalogs.js @@ -7,13 +7,13 @@ const useCatalogs = () => { React.useEffect(() => { const onNewState = () => { const state = core.getState(); - setCatalogs(state.board.groups); + setCatalogs(state.board.items_groups); }; core.on('NewModel', onNewState); core.dispatch({ action: 'Load', args: { - load: 'CatalogGrouped', + load: 'CatalogsGrouped', args: { extra: [] } } }); From 8500b40378018ca162f76da3b344b23859aae8f2 Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Thu, 28 Nov 2019 17:21:28 +0200 Subject: [PATCH 04/15] search: 'no query/groups' cases added --- src/routes/Search/Search.js | 75 +++++++++++++++++++++-------------- src/routes/Search/styles.less | 37 +++++++++++++++++ 2 files changed, 82 insertions(+), 30 deletions(-) diff --git a/src/routes/Search/Search.js b/src/routes/Search/Search.js index 45696f8d4..8dcc6b69b 100644 --- a/src/routes/Search/Search.js +++ b/src/routes/Search/Search.js @@ -1,4 +1,5 @@ const React = require('react'); +const Icon = require('stremio-icons/dom'); const { MainNavBar, MetaRow } = require('stremio/common'); const useSearch = require('./useSearch'); const styles = require('./styles'); @@ -9,36 +10,50 @@ const Search = ({ queryParams }) => {
- {groups.map(({ request, content }, index) => { - switch (content.type) { - case 'Ready': - return ( - - ); - case 'Err': - return ( - - ); - case 'Loading': - return ( - - ); - } - })} + { + !queryParams.has('q') || queryParams.get('q').length === 0 || groups.length === 0 ? +
+
+ +
Search for movies, series, YouTube and TV channels
+
+
+ +
Search for actors, directors and writers
+
+
+ : + groups.map(({ request, content }, index) => { + switch (content.type) { + case 'Ready': + return ( + + ); + case 'Err': + return ( + + ); + case 'Loading': + return ( + + ); + } + }) + }
); diff --git a/src/routes/Search/styles.less b/src/routes/Search/styles.less index 338672b2e..c5f3308a9 100644 --- a/src/routes/Search/styles.less +++ b/src/routes/Search/styles.less @@ -36,6 +36,43 @@ margin-bottom: 2rem; } } + + .message-container { + display: flex; + flex-direction: row; + align-items: flex-start; + justify-content: center; + margin: 5rem; + + .message-content { + flex: 1; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + + .icon { + flex: none; + width: 6rem; + height: 6rem; + margin-bottom: 2rem; + fill: var(--color-surfacelighter40); + } + + .label { + flex-grow: 0; + flex-shrink: 1; + flex-basis: auto; + font-size: 1.2rem; + color: var(--color-surfacelighter40); + text-align: center; + } + + &:not(:last-child) { + margin-right: 5rem;; + } + } + } } } From 921a23b5cda71756ee22833e142628720f253f79 Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Fri, 29 Nov 2019 13:31:02 +0200 Subject: [PATCH 05/15] useSearch now returns the whole search object; --- src/routes/Search/useSearch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/Search/useSearch.js b/src/routes/Search/useSearch.js index 5271ec2b6..9f26678f9 100644 --- a/src/routes/Search/useSearch.js +++ b/src/routes/Search/useSearch.js @@ -7,7 +7,7 @@ const useSearch = (queryParams) => { React.useEffect(() => { const onNewState = () => { const state = core.getState(); - setSearch(state.search.items_groups); + setSearch(state.search); }; core.on('NewModel', onNewState); if (queryParams.has('q')) { From e8faa09b13dc6d0a75e507e0709293cb1996b676 Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Fri, 29 Nov 2019 13:31:20 +0200 Subject: [PATCH 06/15] no metadata case added --- src/routes/Search/Search.js | 71 ++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/src/routes/Search/Search.js b/src/routes/Search/Search.js index 8dcc6b69b..f68eeacfe 100644 --- a/src/routes/Search/Search.js +++ b/src/routes/Search/Search.js @@ -5,13 +5,13 @@ const useSearch = require('./useSearch'); const styles = require('./styles'); const Search = ({ queryParams }) => { - const groups = useSearch(queryParams); + const search = useSearch(queryParams); return (
{ - !queryParams.has('q') || queryParams.get('q').length === 0 || groups.length === 0 ? + !queryParams.has('q') || queryParams.get('q').length === 0 ?
@@ -23,36 +23,43 @@ const Search = ({ queryParams }) => {
: - groups.map(({ request, content }, index) => { - switch (content.type) { - case 'Ready': - return ( - - ); - case 'Err': - return ( - - ); - case 'Loading': - return ( - - ); - } - }) + search.items_groups && search.items_groups.length > 0 && search.items_groups.some(group => group.content.type !== 'Err') ? + search.items_groups.map(({ request, content }, index) => { + switch (content.type) { + case 'Ready': + return ( + + ); + case 'Err': + return ( + + ); + case 'Loading': + return ( + + ); + } + }) + : +
+
+
No metadata was found
+
+
}
From 665e3500c4b8a65a7d8ad1e0e3307d707dce6854 Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Fri, 29 Nov 2019 13:55:19 +0200 Subject: [PATCH 07/15] use search.selected instead of queryParams --- src/routes/Search/Search.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/routes/Search/Search.js b/src/routes/Search/Search.js index f68eeacfe..d38df9347 100644 --- a/src/routes/Search/Search.js +++ b/src/routes/Search/Search.js @@ -11,18 +11,7 @@ const Search = ({ queryParams }) => {
{ - !queryParams.has('q') || queryParams.get('q').length === 0 ? -
-
- -
Search for movies, series, YouTube and TV channels
-
-
- -
Search for actors, directors and writers
-
-
- : + search.selected && search.selected[0][1].length > 0 ? search.items_groups && search.items_groups.length > 0 && search.items_groups.some(group => group.content.type !== 'Err') ? search.items_groups.map(({ request, content }, index) => { switch (content.type) { @@ -60,6 +49,17 @@ const Search = ({ queryParams }) => {
No metadata was found
+ : +
+
+ +
Search for movies, series, YouTube and TV channels
+
+
+ +
Search for actors, directors and writers
+
+
}
From 07cabd2700cf3a65f510590129246f4deeff61ef Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Fri, 29 Nov 2019 16:28:59 +0200 Subject: [PATCH 08/15] onSeeAllButtonClicked prop added in MetaRow --- src/common/MetaRow/MetaRow.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/MetaRow/MetaRow.js b/src/common/MetaRow/MetaRow.js index 9658dff1f..b42153893 100644 --- a/src/common/MetaRow/MetaRow.js +++ b/src/common/MetaRow/MetaRow.js @@ -7,7 +7,7 @@ const MetaItem = require('stremio/common/MetaItem'); const MetaRowPlaceholder = require('./MetaRowPlaceholder'); const styles = require('./styles'); -const MetaRow = ({ className, title, message, items, maximumItemsCount, itemMenuOptions }) => { +const MetaRow = ({ className, title, message, items, maximumItemsCount, itemMenuOptions, onSeeAllButtonClicked }) => { maximumItemsCount = maximumItemsCount !== null && isFinite(maximumItemsCount) ? maximumItemsCount : 20; items = Array.isArray(items) ? items.slice(0, maximumItemsCount) : []; return ( @@ -38,7 +38,7 @@ const MetaRow = ({ className, title, message, items, maximumItemsCount, itemMenu
))}
- @@ -58,7 +58,8 @@ MetaRow.propTypes = { posterShape: PropTypes.string })), maximumItemsCount: PropTypes.number, - itemMenuOptions: PropTypes.any + itemMenuOptions: PropTypes.any, + onSeeAllButtonClicked: PropTypes.func }; module.exports = MetaRow; From 96d9332a9e159bcfabc88abf480f1fb58625a3a4 Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Fri, 29 Nov 2019 16:33:10 +0200 Subject: [PATCH 09/15] 'see all' button shows all relevant items in discover --- src/routes/Search/Search.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/routes/Search/Search.js b/src/routes/Search/Search.js index d38df9347..c2ec29b50 100644 --- a/src/routes/Search/Search.js +++ b/src/routes/Search/Search.js @@ -6,12 +6,15 @@ const styles = require('./styles'); const Search = ({ queryParams }) => { const search = useSearch(queryParams); + const discoverUrls = React.useCallback((request) => { + window.location.replace(`#/discover/${encodeURIComponent(request.base)}/${encodeURIComponent(request.path.id)}/${encodeURIComponent(request.path.type_name)}?search=${search.selected[0][1]}`); + }, [search.selected]); return (
{ - search.selected && search.selected[0][1].length > 0 ? + search.selected && search.selected[0][1] && search.selected[0][1].length > 0 ? search.items_groups && search.items_groups.length > 0 && search.items_groups.some(group => group.content.type !== 'Err') ? search.items_groups.map(({ request, content }, index) => { switch (content.type) { @@ -22,6 +25,7 @@ const Search = ({ queryParams }) => { className={styles['search-row']} title={`${request.path.id} - ${request.path.type_name}`} items={content.content} + onSeeAllButtonClicked={() => discoverUrls(request)} /> ); case 'Err': From 32be8a633a09a9dcb373037310a0efa1891f4ebc Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Fri, 29 Nov 2019 17:37:49 +0200 Subject: [PATCH 10/15] handle 'no requested addons' case --- src/routes/Search/Search.js | 73 ++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/src/routes/Search/Search.js b/src/routes/Search/Search.js index c2ec29b50..f1daff287 100644 --- a/src/routes/Search/Search.js +++ b/src/routes/Search/Search.js @@ -15,42 +15,49 @@ const Search = ({ queryParams }) => {
{ search.selected && search.selected[0][1] && search.selected[0][1].length > 0 ? - search.items_groups && search.items_groups.length > 0 && search.items_groups.some(group => group.content.type !== 'Err') ? - search.items_groups.map(({ request, content }, index) => { - switch (content.type) { - case 'Ready': - return ( - discoverUrls(request)} - /> - ); - case 'Err': - return ( - - ); - case 'Loading': - return ( - - ); - } - }) + search.items_groups && search.items_groups.length > 0 ? + search.items_groups.some(group => group.content.type !== 'Err') ? + search.items_groups.map(({ request, content }, index) => { + switch (content.type) { + case 'Ready': + return ( + discoverUrls(request)} + /> + ); + case 'Err': + return ( + + ); + case 'Loading': + return ( + + ); + } + }) + : +
+
+
No metadata was found
+
+
:
-
No metadata was found
+
No addons were requested for metadata
: From 2ee8f3f1ea0db31015f107091cc065cbec3dbf8a Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Mon, 2 Dec 2019 14:36:14 +0200 Subject: [PATCH 11/15] catalogHref prop added to MetaRow --- src/common/MetaRow/MetaRow.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/MetaRow/MetaRow.js b/src/common/MetaRow/MetaRow.js index b42153893..b416207a3 100644 --- a/src/common/MetaRow/MetaRow.js +++ b/src/common/MetaRow/MetaRow.js @@ -7,7 +7,7 @@ const MetaItem = require('stremio/common/MetaItem'); const MetaRowPlaceholder = require('./MetaRowPlaceholder'); const styles = require('./styles'); -const MetaRow = ({ className, title, message, items, maximumItemsCount, itemMenuOptions, onSeeAllButtonClicked }) => { +const MetaRow = ({ className, title, message, items, maximumItemsCount, itemMenuOptions, catalogHref }) => { maximumItemsCount = maximumItemsCount !== null && isFinite(maximumItemsCount) ? maximumItemsCount : 20; items = Array.isArray(items) ? items.slice(0, maximumItemsCount) : []; return ( @@ -38,7 +38,7 @@ const MetaRow = ({ className, title, message, items, maximumItemsCount, itemMenu
))}
- @@ -59,7 +59,7 @@ MetaRow.propTypes = { })), maximumItemsCount: PropTypes.number, itemMenuOptions: PropTypes.any, - onSeeAllButtonClicked: PropTypes.func + catalogHref: PropTypes.string }; module.exports = MetaRow; From e3811c91e25e6e91a19c0c29c833d6aa2b55d7d1 Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Mon, 2 Dec 2019 14:39:05 +0200 Subject: [PATCH 12/15] search state mapped in the initial state --- src/routes/Search/Search.js | 9 +++------ src/routes/Search/useSearch.js | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/routes/Search/Search.js b/src/routes/Search/Search.js index f1daff287..5e3504ea6 100644 --- a/src/routes/Search/Search.js +++ b/src/routes/Search/Search.js @@ -6,18 +6,15 @@ const styles = require('./styles'); const Search = ({ queryParams }) => { const search = useSearch(queryParams); - const discoverUrls = React.useCallback((request) => { - window.location.replace(`#/discover/${encodeURIComponent(request.base)}/${encodeURIComponent(request.path.id)}/${encodeURIComponent(request.path.type_name)}?search=${search.selected[0][1]}`); - }, [search.selected]); return (
{ - search.selected && search.selected[0][1] && search.selected[0][1].length > 0 ? + search.selected ? search.items_groups && search.items_groups.length > 0 ? search.items_groups.some(group => group.content.type !== 'Err') ? - search.items_groups.map(({ request, content }, index) => { + search.items_groups.map(({ href, request, content }, index) => { switch (content.type) { case 'Ready': return ( @@ -26,7 +23,7 @@ const Search = ({ queryParams }) => { className={styles['search-row']} title={`${request.path.id} - ${request.path.type_name}`} items={content.content} - onSeeAllButtonClicked={() => discoverUrls(request)} + catalogHref={href} /> ); case 'Err': diff --git a/src/routes/Search/useSearch.js b/src/routes/Search/useSearch.js index 9f26678f9..64ae61a19 100644 --- a/src/routes/Search/useSearch.js +++ b/src/routes/Search/useSearch.js @@ -1,13 +1,27 @@ const React = require('react'); const { useServices } = require('stremio/services'); +const mapSearchState = (state) => { + const selected = state.search.selected && state.search.selected[0] && state.search.selected[0][1] && state.search.selected[0][1].length > 0 ? state.search.selected[0][1] : ''; + const items_groups = state.search.items_groups.map((group) => { + group.href = `#/discover/${encodeURIComponent(group.request.base)}/${encodeURIComponent(group.request.path.id)}/${encodeURIComponent(group.request.path.type_name)}?search=${state.search.selected[0][1]}`; + return group; + }); + return { selected, items_groups }; +}; + const useSearch = (queryParams) => { const { core } = useServices(); - const [search, setSearch] = React.useState([]); + const [search, setSearch] = React.useState(() => { + const state = core.getState(); + const search = mapSearchState(state); + return search; + }); React.useEffect(() => { const onNewState = () => { const state = core.getState(); - setSearch(state.search); + const search = mapSearchState(state); + setSearch(search); }; core.on('NewModel', onNewState); if (queryParams.has('q')) { From 373e5b5d39bfafbb8f103162f63eaa77e41e6535 Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Mon, 2 Dec 2019 16:21:23 +0200 Subject: [PATCH 13/15] q renamed to search --- src/common/NavBar/SearchBar/SearchBar.js | 4 ++-- src/routes/Search/useSearch.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/NavBar/SearchBar/SearchBar.js b/src/common/NavBar/SearchBar/SearchBar.js index 5e33d44ec..2097c79af 100644 --- a/src/common/NavBar/SearchBar/SearchBar.js +++ b/src/common/NavBar/SearchBar/SearchBar.js @@ -20,7 +20,7 @@ const SearchBar = ({ className }) => { if (routeActive) { const { search: locationSearch } = UrlUtils.parse(locationHash.slice(1)); const queryParams = new URLSearchParams(locationSearch); - return queryParams.has('q') ? queryParams.get('q') : ''; + return queryParams.has('search') ? queryParams.get('search') : ''; } return ''; @@ -32,7 +32,7 @@ const SearchBar = ({ className }) => { }, [routeActive]); const queryInputOnSubmit = React.useCallback(() => { if (routeActive) { - window.location.replace(`#/search?q=${searchInputRef.current.value}`); + window.location.replace(`#/search?search=${searchInputRef.current.value}`); } }, [routeActive]); React.useEffect(() => { diff --git a/src/routes/Search/useSearch.js b/src/routes/Search/useSearch.js index 64ae61a19..427cb8c9c 100644 --- a/src/routes/Search/useSearch.js +++ b/src/routes/Search/useSearch.js @@ -24,14 +24,14 @@ const useSearch = (queryParams) => { setSearch(search); }; core.on('NewModel', onNewState); - if (queryParams.has('q')) { + if (queryParams.has('search')) { core.dispatch({ action: 'Load', args: { load: 'CatalogsGrouped', args: { extra: [ - ['search', queryParams.get('q')] + ['search', queryParams.get('search')] ] } } From 268d5a6e0b2863705b3682eb67c5d75aa35602b3 Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Mon, 2 Dec 2019 16:22:24 +0200 Subject: [PATCH 14/15] use query for href --- src/routes/Search/useSearch.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/routes/Search/useSearch.js b/src/routes/Search/useSearch.js index 427cb8c9c..331a34143 100644 --- a/src/routes/Search/useSearch.js +++ b/src/routes/Search/useSearch.js @@ -2,9 +2,15 @@ const React = require('react'); const { useServices } = require('stremio/services'); const mapSearchState = (state) => { - const selected = state.search.selected && state.search.selected[0] && state.search.selected[0][1] && state.search.selected[0][1].length > 0 ? state.search.selected[0][1] : ''; + const query = state.search.selected.reduceRight((query, [name, value]) => { + if (name === 'search') { + return value; + } + return query; + }, ''); + const selected = state.search.selected; const items_groups = state.search.items_groups.map((group) => { - group.href = `#/discover/${encodeURIComponent(group.request.base)}/${encodeURIComponent(group.request.path.id)}/${encodeURIComponent(group.request.path.type_name)}?search=${state.search.selected[0][1]}`; + group.href = `#/discover/${encodeURIComponent(group.request.base)}/${encodeURIComponent(group.request.path.id)}/${encodeURIComponent(group.request.path.type_name)}?search=${query}`; return group; }); return { selected, items_groups }; From be1282bd5dedcd8bc097dc35a158e918f81f8eee Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Mon, 2 Dec 2019 16:22:34 +0200 Subject: [PATCH 15/15] searchSelected func added --- src/routes/Search/Search.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/routes/Search/Search.js b/src/routes/Search/Search.js index 5e3504ea6..b91fbea06 100644 --- a/src/routes/Search/Search.js +++ b/src/routes/Search/Search.js @@ -6,12 +6,15 @@ const styles = require('./styles'); const Search = ({ queryParams }) => { const search = useSearch(queryParams); + const searchSelected = React.useMemo(() => { + return search.selected.some(([name, value]) => name === 'search' && value.length > 0) + }, [search.selected]); return (
{ - search.selected ? + searchSelected ? search.items_groups && search.items_groups.length > 0 ? search.items_groups.some(group => group.content.type !== 'Err') ? search.items_groups.map(({ href, request, content }, index) => {