From 8669a4a801368ed8e26d547ead22978f83637a38 Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Mon, 5 Jul 2021 18:03:17 +0500 Subject: [PATCH] migrated search endpoints --- src/providers/ecency/ecency.ts | 125 ++++++++++-------- .../best/container/postsResultsContainer.js | 8 +- 2 files changed, 79 insertions(+), 54 deletions(-) diff --git a/src/providers/ecency/ecency.ts b/src/providers/ecency/ecency.ts index f1a58dbc7..012080920 100644 --- a/src/providers/ecency/ecency.ts +++ b/src/providers/ecency/ecency.ts @@ -398,67 +398,88 @@ export const setPushToken = (data) => * ************************************ */ -export const search = (data) => - new Promise((resolve, reject) => { - searchApi - .post('/search', data) - .then((res) => { - resolve(res.data); - }) - .catch((error) => { - bugsnag.notify(error); - reject(error); - }); - }); +export const search = async (data:{ + q: string, + sort: string, + hideLow: string, + since?: string, + scroll_id?: string +}) => { + try { + const response = await ecencyApi.post('/search-api/search', data); + return response.data; + } catch(error) { + console.warn("Search failed", error); + bugsnag.notify(error); + throw error; + } +} -export const searchPath = (q) => - new Promise((resolve, reject) => { - searchApi - .post('/search-path', { - q, - }) - .then((res) => { - resolve(res.data); - }) - .catch((error) => { - bugsnag.notify(error); - reject(error); - }); - }); -export const searchAccount = (q = '', limit = 20, random = 0) => - new Promise((resolve, reject) => { - searchApi - .post('/search-account', { + /** + * + * @param q query + * @returns array of path strings + */ + export const searchPath = async (q:string) => { + try { + const data = { q }; + const response = await ecencyApi.post('/search-api/search-path', data); + return response.data; + } catch(error){ + console.warn("path search failed", error) + bugsnag.notify(error); + throw error + } + } + + + /** + * + * @param q query + * @param limit number of posts to fetch + * @param random random + * @returns array of accounts + */ + export const searchAccount = async (q:string = '', limit:number = 20, random:number = 0) => { + try { + const data = { q, limit, random, - }) - .then((res) => { - resolve(res.data); - }) - .catch((error) => { - bugsnag.notify(error); - reject(error); - }); - }); + } + const response = await ecencyApi.post(`/search-api/search-account`, data) + return response.data; + } catch(error) { + console.warn("account search failed", error) + bugsnag.notify(error); + throw error; + } + } -export const searchTag = (q = '', limit = 20, random = 0) => - new Promise((resolve, reject) => { - searchApi - .post('/search-tag', { + + /** + * + * @param q query + * @param limit number of posts to fetch + * @param random random + * @returns array of accounts + */ + export const searchTag = async (q:string = '', limit:number = 20, random:number = 0) => { + try { + const data = { q, limit, random, - }) - .then((res) => { - resolve(res.data); - }) - .catch((error) => { - bugsnag.notify(error); - reject(error); - }); - }); + } + const response = await ecencyApi.post(`/search-api/search-tag`, data); + return response.data; + } catch(error) { + console.warn("tag search failed", error) + bugsnag.notify(error); + throw error + } + } diff --git a/src/screens/searchResult/screen/tabs/best/container/postsResultsContainer.js b/src/screens/searchResult/screen/tabs/best/container/postsResultsContainer.js index a5f538df4..397d43656 100644 --- a/src/screens/searchResult/screen/tabs/best/container/postsResultsContainer.js +++ b/src/screens/searchResult/screen/tabs/best/container/postsResultsContainer.js @@ -99,9 +99,13 @@ const PostsResultsContainer = ({ children, navigation, searchValue }) => { const _loadMore = (index, value) => { if (scrollId && searchValue) { - search({ q: `${searchValue} type:post`, sort, scroll_id: scrollId }).then((res) => { + search({ q: `${searchValue} type:post`, sort, scroll_id: scrollId }) + .then((res) => { setData([...data, ...res.results]); - }); + }) + .catch(()=>{ + console.warn("Search Failed"); + }) } };