From b2ef2617607d4086b390c5ecc8074f894c6a5248 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Mon, 10 Feb 2020 12:04:34 +0100 Subject: [PATCH] Resolved search updates (#273) * add doResolvedSearch actions which returns resolved search results * add recommended content selector * update ResolvedSearchResult type * support for multiple pages of resolved search results * add nsfw flag --- dist/bundle.es.js | 5 +++-- src/redux/actions/search.js | 15 +++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 9153398..c83f84b 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -4112,7 +4112,7 @@ const doSearch = (rawQuery, searchOptions) => (dispatch, getState) => { }; const doResolvedSearch = (rawQuery, size, // only pass in if you don't want to use the users setting (ex: related content) -from, isBackgroundSearch = false, options = {}) => (dispatch, getState) => { +from, isBackgroundSearch = false, options = {}, nsfw) => (dispatch, getState) => { const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' '); if (!query) { @@ -4155,7 +4155,8 @@ from, isBackgroundSearch = false, options = {}) => (dispatch, getState) => { dispatch(doUpdateSearchQuery(query)); } - fetch(`${CONNECTION_STRING}search?resolve=true&${queryWithOptions}`).then(handleFetchResponse).then(data => { + const fetchUrl = nsfw ? `${CONNECTION_STRING}search?resolve=true&${queryWithOptions}` : `${CONNECTION_STRING}search?resolve=true&nsfw=false&${queryWithOptions}`; + fetch(fetchUrl).then(handleFetchResponse).then(data => { const results = []; data.forEach(result => { diff --git a/src/redux/actions/search.js b/src/redux/actions/search.js index bee1350..6094277 100644 --- a/src/redux/actions/search.js +++ b/src/redux/actions/search.js @@ -166,13 +166,13 @@ export const doSearch = (rawQuery: string, searchOptions: SearchOptions) => ( export const doResolvedSearch = ( rawQuery: string, - size?: number, // only pass in if you don't want to use the users setting (ex: related content) - from?: number, - isBackgroundSearch?: boolean = false, + size: ?number, // only pass in if you don't want to use the users setting (ex: related content) + from: ?number, + isBackgroundSearch: boolean = false, options: { related_to?: string, - // nsfw here - } = {} + } = {}, + nsfw: boolean ) => (dispatch: Dispatch, getState: GetState) => { const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' '); @@ -218,7 +218,10 @@ export const doResolvedSearch = ( dispatch(doUpdateSearchQuery(query)); } - fetch(`${CONNECTION_STRING}search?resolve=true&${queryWithOptions}`) + const fetchUrl = nsfw + ? `${CONNECTION_STRING}search?resolve=true&${queryWithOptions}` + : `${CONNECTION_STRING}search?resolve=true&nsfw=false&${queryWithOptions}`; + fetch(fetchUrl) .then(handleFetchResponse) .then((data: Array) => { const results = [];