From 35c44293193a0068c0e6dead7129523fe65d6a8f Mon Sep 17 00:00:00 2001 From: Mirza Hanan Date: Tue, 24 Sep 2024 15:53:24 +0500 Subject: [PATCH 1/2] fix(search-filter): connect Search filter and endpoint request --- src/stores/useDataStore/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/stores/useDataStore/index.ts b/src/stores/useDataStore/index.ts index 155222346..80d12d6d0 100644 --- a/src/stores/useDataStore/index.ts +++ b/src/stores/useDataStore/index.ts @@ -18,6 +18,10 @@ export type FetchNodeParams = { skip_cache?: string free?: string media_type?: string + node_type?: string + limit?: string + depth?: string + top_node_count?: string } export type SidebarFilterWithCount = { @@ -136,7 +140,7 @@ export const useDataStore = create()( devtools((set, get) => ({ ...defaultData, - fetchData: async (setBudget, setAbortRequests, AISearchQuery = '') => { + fetchData: async (setBudget, setAbortRequests, AISearchQuery = '', params: FetchNodeParams = {}) => { const { dataInitial: existingData, filters } = get() const currentPage = filters.skip const itemsPerPage = filters.limit @@ -174,6 +178,7 @@ export const useDataStore = create()( const updatedParams = { ...withoutNodeType, + ...params, ...ai, skip: currentPage === 0 ? String(currentPage * itemsPerPage) : String(currentPage * itemsPerPage + 1), limit: word ? '25' : String(itemsPerPage), From ccf1a53093811f3663f80f5b2e26ad6880838761 Mon Sep 17 00:00:00 2001 From: Mirza Hanan Date: Thu, 26 Sep 2024 19:04:04 +0500 Subject: [PATCH 2/2] fix(search-filter): connect Search filter and endpoint request --- src/components/App/SideBar/FilterSearch/index.tsx | 6 +----- src/stores/useDataStore/index.ts | 12 +++++------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/components/App/SideBar/FilterSearch/index.tsx b/src/components/App/SideBar/FilterSearch/index.tsx index b61c43786..3d9f156d3 100644 --- a/src/components/App/SideBar/FilterSearch/index.tsx +++ b/src/components/App/SideBar/FilterSearch/index.tsx @@ -6,7 +6,6 @@ import PlusIcon from '~/components/Icons/PlusIcon' import { SchemaExtended } from '~/components/ModalsContainer/BlueprintModal/types' import { Flex } from '~/components/common/Flex' import { useDataStore } from '~/stores/useDataStore' -import { useUserStore } from '~/stores/useUserStore' import { colors } from '~/utils/colors' import { Hops } from './Hops' import { MaxResults } from './MaxResults' @@ -42,8 +41,7 @@ export const FilterSearch = ({ ) } - const { setFilters, fetchData, setAbortRequests } = useDataStore((s) => s) - const { setBudget } = useUserStore((s) => s) + const { setFilters } = useDataStore((s) => s) const [selectedTypes, setSelectedTypes] = useState(defaultValues.selectedTypes) const [hops, setHops] = useState(defaultValues.hops) const [sourceNodes, setSourceNodes] = useState(defaultValues.sourceNodes) @@ -74,8 +72,6 @@ export const FilterSearch = ({ setAnchorEl(null) onClose() - - await fetchData(setBudget, setAbortRequests) } const uniqueSchemas = (showAllSchemas ? schemaAll : schemaAll.slice(0, 4)).filter( diff --git a/src/stores/useDataStore/index.ts b/src/stores/useDataStore/index.ts index cdac97377..bb30fa412 100644 --- a/src/stores/useDataStore/index.ts +++ b/src/stores/useDataStore/index.ts @@ -18,10 +18,6 @@ export type FetchNodeParams = { skip_cache?: string free?: string media_type?: string - node_type?: string - limit?: string - depth?: string - top_node_count?: string } export type SidebarFilterWithCount = { @@ -141,7 +137,7 @@ export const useDataStore = create()( devtools((set, get) => ({ ...defaultData, - fetchData: async (setBudget, setAbortRequests, AISearchQuery = '', params: FetchNodeParams = {}) => { + fetchData: async (setBudget, setAbortRequests, AISearchQuery = '') => { const { dataInitial: existingData, filters } = get() const currentPage = filters.skip const itemsPerPage = filters.limit @@ -179,7 +175,6 @@ export const useDataStore = create()( const updatedParams = { ...withoutNodeType, - ...params, ...ai, skip: currentPage === 0 ? String(currentPage * itemsPerPage) : String(currentPage * itemsPerPage + 1), limit: word ? '25' : String(itemsPerPage), @@ -287,7 +282,10 @@ export const useDataStore = create()( fetchData() }, resetDataNew: () => null, - setFilters: (filters: FilterParams) => set((state) => ({ filters: { ...state.filters, ...filters, page: 0 } })), + setFilters: (filters: Partial) => { + set((state) => ({ filters: { ...state.filters, ...filters, skip: 0 } })) + get().fetchData(get().setBudget, get().setAbortRequests) + }, setSidebarFilterCounts: (sidebarFilterCounts) => set({ sidebarFilterCounts }), setTrendingTopics: (trendingTopics) => set({ trendingTopics }), setStats: (stats) => set({ stats }),