From a41d1a97e8a6a42b10e8ca450e2d7469bf926eb8 Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Thu, 28 Sep 2023 16:34:01 +0330 Subject: [PATCH] chore: remove redundant code --- .../PostSearchContainer/PostSearch.context.ts | 3 --- .../PostSearchContainer.tsx | 5 ++-- src/queries/usePostSearch.query.ts | 23 +++++++------------ 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/containers/PostSearchContainer/PostSearch.context.ts b/src/containers/PostSearchContainer/PostSearch.context.ts index b489c33..fb1b0fa 100644 --- a/src/containers/PostSearchContainer/PostSearch.context.ts +++ b/src/containers/PostSearchContainer/PostSearch.context.ts @@ -10,7 +10,6 @@ export type PostSearchContextType = { query?: string fetching?: boolean results: Block[] - mappedResults?: Record } export const PostSearchContext = React.createContext({ @@ -18,14 +17,12 @@ export const PostSearchContext = React.createContext({ query: '', fetching: false, results: [], - mappedResults: {}, }) export const usePostSearch = () => useContext(PostSearchContext) || { query: '', results: [], - mappedResults: {}, active: false, fetching: false, } diff --git a/src/containers/PostSearchContainer/PostSearchContainer.tsx b/src/containers/PostSearchContainer/PostSearchContainer.tsx index 3d7fdde..45677e6 100644 --- a/src/containers/PostSearchContainer/PostSearchContainer.tsx +++ b/src/containers/PostSearchContainer/PostSearchContainer.tsx @@ -73,7 +73,7 @@ export const PostSearchContainer: React.FC< globalMode={false} showCloseButton fetching={res.isLoading} - numberOfResults={res.data?.result?.length} + numberOfResults={res.data?.length} /> 0, - results: res.data?.result || [], - mappedResults: res.data?.mapped || {}, + results: res.data || [], }} > {children} diff --git a/src/queries/usePostSearch.query.ts b/src/queries/usePostSearch.query.ts index 0ef478a..0257abd 100644 --- a/src/queries/usePostSearch.query.ts +++ b/src/queries/usePostSearch.query.ts @@ -14,21 +14,14 @@ export const usePostSearchQuery = ({ limit?: number active?: boolean }) => - useQuery<{ - result: LPE.Search.ResultBlockItem[] - mapped: Record - }>(['post-search-query', active, id, query, limit], async () => + useQuery(['post-search-query', active, id, query, limit], async () => !active - ? { result: [], mapped: {} } - : api.searchPostBlocks({ limit, id, query, skip: 0 }).then((res) => { - let items = res.data.blocks as LPE.Search.ResultBlockItem[] - items = items.filter(searchBlocksBasicFilter) - - return { - result: items, - mapped: Object.fromEntries( - items.map((item) => [item.data.id, item]), + ? [] + : api + .searchPostBlocks({ limit, id, query, skip: 0 }) + .then((res) => + (res.data.blocks as LPE.Search.ResultBlockItem[]).filter( + searchBlocksBasicFilter, ), - } - }), + ), )