chore: remove redundant code
This commit is contained in:
parent
06c1fd0e54
commit
a41d1a97e8
|
@ -10,7 +10,6 @@ export type PostSearchContextType = {
|
|||
query?: string
|
||||
fetching?: boolean
|
||||
results: Block[]
|
||||
mappedResults?: Record<string, Block>
|
||||
}
|
||||
|
||||
export const PostSearchContext = React.createContext<PostSearchContextType>({
|
||||
|
@ -18,14 +17,12 @@ export const PostSearchContext = React.createContext<PostSearchContextType>({
|
|||
query: '',
|
||||
fetching: false,
|
||||
results: [],
|
||||
mappedResults: {},
|
||||
})
|
||||
|
||||
export const usePostSearch = () =>
|
||||
useContext(PostSearchContext) || {
|
||||
query: '',
|
||||
results: [],
|
||||
mappedResults: {},
|
||||
active: false,
|
||||
fetching: false,
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ export const PostSearchContainer: React.FC<
|
|||
globalMode={false}
|
||||
showCloseButton
|
||||
fetching={res.isLoading}
|
||||
numberOfResults={res.data?.result?.length}
|
||||
numberOfResults={res.data?.length}
|
||||
/>
|
||||
</SearchBoxContainer>
|
||||
<PostSearchContext.Provider
|
||||
|
@ -81,8 +81,7 @@ export const PostSearchContainer: React.FC<
|
|||
query,
|
||||
fetching: res.isLoading,
|
||||
active: active && query.length > 0,
|
||||
results: res.data?.result || [],
|
||||
mappedResults: res.data?.mapped || {},
|
||||
results: res.data || [],
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
|
|
@ -14,21 +14,14 @@ export const usePostSearchQuery = ({
|
|||
limit?: number
|
||||
active?: boolean
|
||||
}) =>
|
||||
useQuery<{
|
||||
result: LPE.Search.ResultBlockItem[]
|
||||
mapped: Record<string, LPE.Search.ResultBlockItem>
|
||||
}>(['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,
|
||||
),
|
||||
}
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue