mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-20 10:42:12 +00:00
search adapted with changes in core
This commit is contained in:
parent
86bc5b0c60
commit
8500615c79
2 changed files with 36 additions and 45 deletions
|
|
@ -38,7 +38,7 @@ const Search = ({ queryParams }) => {
|
|||
</div>
|
||||
</div>
|
||||
:
|
||||
search.catalog_resources.length === 0 ?
|
||||
search.catalogs.length === 0 ?
|
||||
<div className={styles['message-container']}>
|
||||
<Image
|
||||
className={styles['image']}
|
||||
|
|
@ -48,12 +48,12 @@ const Search = ({ queryParams }) => {
|
|||
<div className={styles['message-label']}>No addons were requested for catalogs!</div>
|
||||
</div>
|
||||
:
|
||||
search.catalog_resources.map((catalog_resource, index) => {
|
||||
const title = `${catalog_resource.origin} - ${catalog_resource.request.path.id} ${catalog_resource.request.path.type_name}`;
|
||||
switch (catalog_resource.content.type) {
|
||||
search.catalogs.map((catalog, index) => {
|
||||
const title = `${catalog.addon_name} - ${catalog.request.path.id} ${catalog.request.path.type}`;
|
||||
switch (catalog.content.type) {
|
||||
case 'Ready': {
|
||||
const posterShape = catalog_resource.content.content.length > 0 ?
|
||||
catalog_resource.content.content[0].posterShape
|
||||
const posterShape = catalog.content.content.length > 0 ?
|
||||
catalog.content.content[0].posterShape
|
||||
:
|
||||
null;
|
||||
return (
|
||||
|
|
@ -61,21 +61,29 @@ const Search = ({ queryParams }) => {
|
|||
key={index}
|
||||
className={classnames(styles['search-row'], styles['search-row-poster'], { [styles[`search-row-${posterShape}`]]: typeof posterShape === 'string' })}
|
||||
title={title}
|
||||
items={catalog_resource.content.content}
|
||||
items={catalog.content.content}
|
||||
itemComponent={MetaItem}
|
||||
deepLinks={catalog_resource.deepLinks}
|
||||
deepLinks={catalog.deepLinks}
|
||||
/>
|
||||
);
|
||||
}
|
||||
case 'Err': {
|
||||
const message = `Error(${catalog_resource.content.content.type})`;
|
||||
const type = `Error(${catalog.content.content.type})`;
|
||||
const description = catalog.content.content.type === 'UnexpectedResponse' ?
|
||||
catalog.content.content.content
|
||||
:
|
||||
catalog.content.content.type === 'Env' ?
|
||||
catalog.content.content.content.message
|
||||
:
|
||||
'';
|
||||
const message = `${type}${description !== null ? ` ${description}` : null}`;
|
||||
return (
|
||||
<MetaRow
|
||||
key={index}
|
||||
className={styles['search-row']}
|
||||
title={title}
|
||||
message={message}
|
||||
deepLinks={catalog_resource.deepLinks}
|
||||
deepLinks={catalog.deepLinks}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -85,7 +93,7 @@ const Search = ({ queryParams }) => {
|
|||
key={index}
|
||||
className={classnames(styles['search-row'], styles['search-row-poster'])}
|
||||
title={title}
|
||||
deepLinks={catalog_resource.deepLinks}
|
||||
deepLinks={catalog.deepLinks}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,48 +1,36 @@
|
|||
// Copyright (C) 2017-2020 Smart code 203358507
|
||||
|
||||
const React = require('react');
|
||||
const { deepLinking, useModelState } = require('stremio/common');
|
||||
const { useModelState } = require('stremio/common');
|
||||
|
||||
const initSearchState = () => ({
|
||||
const init = () => ({
|
||||
selected: null,
|
||||
catalog_resources: []
|
||||
catalogs: []
|
||||
});
|
||||
|
||||
const mapSearchStateWithCtx = (search, ctx) => {
|
||||
const selected = search.selected;
|
||||
const catalog_resources = search.catalog_resources.map((catalog_resource) => {
|
||||
const request = catalog_resource.request;
|
||||
const content = catalog_resource.content.type === 'Ready' ?
|
||||
const map = (search) => ({
|
||||
...search,
|
||||
catalogs: search.catalogs.map((catalog) => ({
|
||||
...catalog,
|
||||
content: catalog.content.type === 'Ready' ?
|
||||
{
|
||||
type: 'Ready',
|
||||
content: catalog_resource.content.content.map((metaItem, _, metaItems) => ({
|
||||
...catalog.content,
|
||||
content: catalog.content.content.map((metaItem, _, metaItems) => ({
|
||||
type: metaItem.type,
|
||||
name: metaItem.name,
|
||||
poster: metaItem.poster,
|
||||
posterShape: metaItems[0].posterShape,
|
||||
deepLinks: deepLinking.withMetaItem({ metaItem })
|
||||
deepLinks: metaItem.deep_links
|
||||
}))
|
||||
}
|
||||
:
|
||||
catalog_resource.content;
|
||||
const origin = ctx.profile.addons.reduce((origin, addon) => {
|
||||
if (addon.transportUrl === catalog_resource.request.base) {
|
||||
return typeof addon.manifest.name === 'string' && addon.manifest.name.length > 0 ?
|
||||
addon.manifest.name
|
||||
:
|
||||
addon.manifest.id;
|
||||
}
|
||||
|
||||
return origin;
|
||||
}, catalog_resource.request.base);
|
||||
const deepLinks = deepLinking.withCatalog({ request });
|
||||
return { request, content, origin, deepLinks };
|
||||
});
|
||||
return { selected, catalog_resources };
|
||||
};
|
||||
catalog.content,
|
||||
deepLinks: catalog.deep_links
|
||||
}))
|
||||
});
|
||||
|
||||
const useSearch = (queryParams) => {
|
||||
const loadSearchAction = React.useMemo(() => {
|
||||
const action = React.useMemo(() => {
|
||||
if (queryParams.has('search') && queryParams.get('search').length > 0) {
|
||||
return {
|
||||
action: 'Load',
|
||||
|
|
@ -61,12 +49,7 @@ const useSearch = (queryParams) => {
|
|||
};
|
||||
}
|
||||
}, [queryParams]);
|
||||
return useModelState({
|
||||
model: 'search',
|
||||
action: loadSearchAction,
|
||||
mapWithCtx: mapSearchStateWithCtx,
|
||||
init: initSearchState
|
||||
});
|
||||
return useModelState({ model: 'search', action, map, init });
|
||||
};
|
||||
|
||||
module.exports = useSearch;
|
||||
|
|
|
|||
Loading…
Reference in a new issue