| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import type { | 
					
						
							|  |  |  |   ReactNode, | 
					
						
							|  |  |  | } from 'react' | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   useCallback, | 
					
						
							|  |  |  |   useEffect, | 
					
						
							|  |  |  |   useMemo, | 
					
						
							|  |  |  |   useRef, | 
					
						
							|  |  |  |   useState, | 
					
						
							|  |  |  | } from 'react' | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   createContext, | 
					
						
							|  |  |  |   useContextSelector, | 
					
						
							|  |  |  | } from 'use-context-selector' | 
					
						
							|  |  |  | import { PLUGIN_TYPE_SEARCH_MAP } from './plugin-type-switch' | 
					
						
							|  |  |  | import type { Plugin } from '../types' | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   getValidCategoryKeys, | 
					
						
							|  |  |  |   getValidTagKeys, | 
					
						
							|  |  |  | } from '../utils' | 
					
						
							|  |  |  | import type { | 
					
						
							|  |  |  |   MarketplaceCollection, | 
					
						
							|  |  |  |   PluginsSort, | 
					
						
							|  |  |  |   SearchParams, | 
					
						
							|  |  |  |   SearchParamsFromCollection, | 
					
						
							|  |  |  | } from './types' | 
					
						
							|  |  |  | import { DEFAULT_SORT } from './constants' | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   useMarketplaceCollectionsAndPlugins, | 
					
						
							|  |  |  |   useMarketplaceContainerScroll, | 
					
						
							|  |  |  |   useMarketplacePlugins, | 
					
						
							|  |  |  | } from './hooks' | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   getMarketplaceListCondition, | 
					
						
							|  |  |  |   getMarketplaceListFilterType, | 
					
						
							| 
									
										
										
										
											2025-04-10 11:18:43 +08:00
										 |  |  |   updateSearchParams, | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | } from './utils' | 
					
						
							|  |  |  | import { useInstalledPluginList } from '@/service/use-plugins' | 
					
						
							| 
									
										
										
										
											2025-04-10 11:18:43 +08:00
										 |  |  | import { debounce, noop } from 'lodash-es' | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export type MarketplaceContextValue = { | 
					
						
							|  |  |  |   intersected: boolean | 
					
						
							|  |  |  |   setIntersected: (intersected: boolean) => void | 
					
						
							|  |  |  |   searchPluginText: string | 
					
						
							|  |  |  |   handleSearchPluginTextChange: (text: string) => void | 
					
						
							|  |  |  |   filterPluginTags: string[] | 
					
						
							|  |  |  |   handleFilterPluginTagsChange: (tags: string[]) => void | 
					
						
							|  |  |  |   activePluginType: string | 
					
						
							|  |  |  |   handleActivePluginTypeChange: (type: string) => void | 
					
						
							|  |  |  |   page: number | 
					
						
							|  |  |  |   handlePageChange: (page: number) => void | 
					
						
							|  |  |  |   plugins?: Plugin[] | 
					
						
							|  |  |  |   pluginsTotal?: number | 
					
						
							|  |  |  |   resetPlugins: () => void | 
					
						
							|  |  |  |   sort: PluginsSort | 
					
						
							|  |  |  |   handleSortChange: (sort: PluginsSort) => void | 
					
						
							|  |  |  |   handleQueryPlugins: () => void | 
					
						
							|  |  |  |   handleMoreClick: (searchParams: SearchParamsFromCollection) => void | 
					
						
							|  |  |  |   marketplaceCollectionsFromClient?: MarketplaceCollection[] | 
					
						
							|  |  |  |   setMarketplaceCollectionsFromClient: (collections: MarketplaceCollection[]) => void | 
					
						
							|  |  |  |   marketplaceCollectionPluginsMapFromClient?: Record<string, Plugin[]> | 
					
						
							|  |  |  |   setMarketplaceCollectionPluginsMapFromClient: (map: Record<string, Plugin[]>) => void | 
					
						
							|  |  |  |   isLoading: boolean | 
					
						
							|  |  |  |   isSuccessCollections: boolean | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const MarketplaceContext = createContext<MarketplaceContextValue>({ | 
					
						
							|  |  |  |   intersected: true, | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  |   setIntersected: noop, | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   searchPluginText: '', | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  |   handleSearchPluginTextChange: noop, | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   filterPluginTags: [], | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  |   handleFilterPluginTagsChange: noop, | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   activePluginType: 'all', | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  |   handleActivePluginTypeChange: noop, | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   page: 1, | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  |   handlePageChange: noop, | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   plugins: undefined, | 
					
						
							|  |  |  |   pluginsTotal: 0, | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  |   resetPlugins: noop, | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   sort: DEFAULT_SORT, | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  |   handleSortChange: noop, | 
					
						
							|  |  |  |   handleQueryPlugins: noop, | 
					
						
							|  |  |  |   handleMoreClick: noop, | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   marketplaceCollectionsFromClient: [], | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  |   setMarketplaceCollectionsFromClient: noop, | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   marketplaceCollectionPluginsMapFromClient: {}, | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  |   setMarketplaceCollectionPluginsMapFromClient: noop, | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   isLoading: false, | 
					
						
							|  |  |  |   isSuccessCollections: false, | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type MarketplaceContextProviderProps = { | 
					
						
							|  |  |  |   children: ReactNode | 
					
						
							|  |  |  |   searchParams?: SearchParams | 
					
						
							|  |  |  |   shouldExclude?: boolean | 
					
						
							|  |  |  |   scrollContainerId?: string | 
					
						
							| 
									
										
										
										
											2025-04-10 11:18:43 +08:00
										 |  |  |   showSearchParams?: boolean | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function useMarketplaceContext(selector: (value: MarketplaceContextValue) => any) { | 
					
						
							|  |  |  |   return useContextSelector(MarketplaceContext, selector) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const MarketplaceContextProvider = ({ | 
					
						
							|  |  |  |   children, | 
					
						
							|  |  |  |   searchParams, | 
					
						
							|  |  |  |   shouldExclude, | 
					
						
							|  |  |  |   scrollContainerId, | 
					
						
							| 
									
										
										
										
											2025-04-10 11:18:43 +08:00
										 |  |  |   showSearchParams, | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | }: MarketplaceContextProviderProps) => { | 
					
						
							|  |  |  |   const { data, isSuccess } = useInstalledPluginList(!shouldExclude) | 
					
						
							|  |  |  |   const exclude = useMemo(() => { | 
					
						
							|  |  |  |     if (shouldExclude) | 
					
						
							|  |  |  |       return data?.plugins.map(plugin => plugin.plugin_id) | 
					
						
							|  |  |  |   }, [data?.plugins, shouldExclude]) | 
					
						
							|  |  |  |   const queryFromSearchParams = searchParams?.q || '' | 
					
						
							|  |  |  |   const tagsFromSearchParams = searchParams?.tags ? getValidTagKeys(searchParams.tags.split(',')) : [] | 
					
						
							|  |  |  |   const hasValidTags = !!tagsFromSearchParams.length | 
					
						
							|  |  |  |   const hasValidCategory = getValidCategoryKeys(searchParams?.category) | 
					
						
							|  |  |  |   const categoryFromSearchParams = hasValidCategory || PLUGIN_TYPE_SEARCH_MAP.all | 
					
						
							|  |  |  |   const [intersected, setIntersected] = useState(true) | 
					
						
							|  |  |  |   const [searchPluginText, setSearchPluginText] = useState(queryFromSearchParams) | 
					
						
							|  |  |  |   const searchPluginTextRef = useRef(searchPluginText) | 
					
						
							|  |  |  |   const [filterPluginTags, setFilterPluginTags] = useState<string[]>(tagsFromSearchParams) | 
					
						
							|  |  |  |   const filterPluginTagsRef = useRef(filterPluginTags) | 
					
						
							|  |  |  |   const [activePluginType, setActivePluginType] = useState(categoryFromSearchParams) | 
					
						
							|  |  |  |   const activePluginTypeRef = useRef(activePluginType) | 
					
						
							|  |  |  |   const [page, setPage] = useState(1) | 
					
						
							|  |  |  |   const pageRef = useRef(page) | 
					
						
							|  |  |  |   const [sort, setSort] = useState(DEFAULT_SORT) | 
					
						
							|  |  |  |   const sortRef = useRef(sort) | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     marketplaceCollections: marketplaceCollectionsFromClient, | 
					
						
							|  |  |  |     setMarketplaceCollections: setMarketplaceCollectionsFromClient, | 
					
						
							|  |  |  |     marketplaceCollectionPluginsMap: marketplaceCollectionPluginsMapFromClient, | 
					
						
							|  |  |  |     setMarketplaceCollectionPluginsMap: setMarketplaceCollectionPluginsMapFromClient, | 
					
						
							|  |  |  |     queryMarketplaceCollectionsAndPlugins, | 
					
						
							|  |  |  |     isLoading, | 
					
						
							|  |  |  |     isSuccess: isSuccessCollections, | 
					
						
							|  |  |  |   } = useMarketplaceCollectionsAndPlugins() | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     plugins, | 
					
						
							|  |  |  |     total: pluginsTotal, | 
					
						
							|  |  |  |     resetPlugins, | 
					
						
							|  |  |  |     queryPlugins, | 
					
						
							|  |  |  |     queryPluginsWithDebounced, | 
					
						
							| 
									
										
										
										
											2025-03-24 15:17:12 +08:00
										 |  |  |     cancelQueryPluginsWithDebounced, | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |     isLoading: isPluginsLoading, | 
					
						
							|  |  |  |   } = useMarketplacePlugins() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     if (queryFromSearchParams || hasValidTags || hasValidCategory) { | 
					
						
							|  |  |  |       queryPlugins({ | 
					
						
							|  |  |  |         query: queryFromSearchParams, | 
					
						
							|  |  |  |         category: hasValidCategory, | 
					
						
							|  |  |  |         tags: hasValidTags ? tagsFromSearchParams : [], | 
					
						
							|  |  |  |         sortBy: sortRef.current.sortBy, | 
					
						
							|  |  |  |         sortOrder: sortRef.current.sortOrder, | 
					
						
							|  |  |  |         type: getMarketplaceListFilterType(activePluginTypeRef.current), | 
					
						
							|  |  |  |         page: pageRef.current, | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2025-04-10 11:18:43 +08:00
										 |  |  |       const url = new URL(window.location.href) | 
					
						
							|  |  |  |       if (searchParams?.language) | 
					
						
							|  |  |  |         url.searchParams.set('language', searchParams?.language) | 
					
						
							|  |  |  |       history.replaceState({}, '', url) | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       if (shouldExclude && isSuccess) { | 
					
						
							|  |  |  |         queryMarketplaceCollectionsAndPlugins({ | 
					
						
							|  |  |  |           exclude, | 
					
						
							|  |  |  |           type: getMarketplaceListFilterType(activePluginTypeRef.current), | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   // eslint-disable-next-line react-hooks/exhaustive-deps
 | 
					
						
							|  |  |  |   }, [queryPlugins, queryMarketplaceCollectionsAndPlugins, isSuccess, exclude]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const handleQueryMarketplaceCollectionsAndPlugins = useCallback(() => { | 
					
						
							|  |  |  |     queryMarketplaceCollectionsAndPlugins({ | 
					
						
							|  |  |  |       category: activePluginTypeRef.current === PLUGIN_TYPE_SEARCH_MAP.all ? undefined : activePluginTypeRef.current, | 
					
						
							|  |  |  |       condition: getMarketplaceListCondition(activePluginTypeRef.current), | 
					
						
							|  |  |  |       exclude, | 
					
						
							|  |  |  |       type: getMarketplaceListFilterType(activePluginTypeRef.current), | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     resetPlugins() | 
					
						
							|  |  |  |   }, [exclude, queryMarketplaceCollectionsAndPlugins, resetPlugins]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-10 11:18:43 +08:00
										 |  |  |   const debouncedUpdateSearchParams = useMemo(() => debounce(() => { | 
					
						
							|  |  |  |     updateSearchParams({ | 
					
						
							|  |  |  |       query: searchPluginTextRef.current, | 
					
						
							|  |  |  |       category: activePluginTypeRef.current, | 
					
						
							|  |  |  |       tags: filterPluginTagsRef.current, | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   }, 500), []) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const handleUpdateSearchParams = useCallback((debounced?: boolean) => { | 
					
						
							|  |  |  |     if (!showSearchParams) | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     if (debounced) { | 
					
						
							|  |  |  |       debouncedUpdateSearchParams() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       updateSearchParams({ | 
					
						
							|  |  |  |         query: searchPluginTextRef.current, | 
					
						
							|  |  |  |         category: activePluginTypeRef.current, | 
					
						
							|  |  |  |         tags: filterPluginTagsRef.current, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }, [debouncedUpdateSearchParams, showSearchParams]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   const handleQueryPlugins = useCallback((debounced?: boolean) => { | 
					
						
							| 
									
										
										
										
											2025-04-10 11:18:43 +08:00
										 |  |  |     handleUpdateSearchParams(debounced) | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |     if (debounced) { | 
					
						
							|  |  |  |       queryPluginsWithDebounced({ | 
					
						
							|  |  |  |         query: searchPluginTextRef.current, | 
					
						
							|  |  |  |         category: activePluginTypeRef.current === PLUGIN_TYPE_SEARCH_MAP.all ? undefined : activePluginTypeRef.current, | 
					
						
							|  |  |  |         tags: filterPluginTagsRef.current, | 
					
						
							|  |  |  |         sortBy: sortRef.current.sortBy, | 
					
						
							|  |  |  |         sortOrder: sortRef.current.sortOrder, | 
					
						
							|  |  |  |         exclude, | 
					
						
							|  |  |  |         type: getMarketplaceListFilterType(activePluginTypeRef.current), | 
					
						
							|  |  |  |         page: pageRef.current, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       queryPlugins({ | 
					
						
							|  |  |  |         query: searchPluginTextRef.current, | 
					
						
							|  |  |  |         category: activePluginTypeRef.current === PLUGIN_TYPE_SEARCH_MAP.all ? undefined : activePluginTypeRef.current, | 
					
						
							|  |  |  |         tags: filterPluginTagsRef.current, | 
					
						
							|  |  |  |         sortBy: sortRef.current.sortBy, | 
					
						
							|  |  |  |         sortOrder: sortRef.current.sortOrder, | 
					
						
							|  |  |  |         exclude, | 
					
						
							|  |  |  |         type: getMarketplaceListFilterType(activePluginTypeRef.current), | 
					
						
							|  |  |  |         page: pageRef.current, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-04-10 11:18:43 +08:00
										 |  |  |   }, [exclude, queryPluginsWithDebounced, queryPlugins, handleUpdateSearchParams]) | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const handleQuery = useCallback((debounced?: boolean) => { | 
					
						
							|  |  |  |     if (!searchPluginTextRef.current && !filterPluginTagsRef.current.length) { | 
					
						
							| 
									
										
										
										
											2025-04-10 11:18:43 +08:00
										 |  |  |       handleUpdateSearchParams(debounced) | 
					
						
							| 
									
										
										
										
											2025-03-24 15:17:12 +08:00
										 |  |  |       cancelQueryPluginsWithDebounced() | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |       handleQueryMarketplaceCollectionsAndPlugins() | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     handleQueryPlugins(debounced) | 
					
						
							| 
									
										
										
										
											2025-04-10 11:18:43 +08:00
										 |  |  |   }, [handleQueryMarketplaceCollectionsAndPlugins, handleQueryPlugins, cancelQueryPluginsWithDebounced, handleUpdateSearchParams]) | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const handleSearchPluginTextChange = useCallback((text: string) => { | 
					
						
							|  |  |  |     setSearchPluginText(text) | 
					
						
							|  |  |  |     searchPluginTextRef.current = text | 
					
						
							|  |  |  |     setPage(1) | 
					
						
							|  |  |  |     pageRef.current = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     handleQuery(true) | 
					
						
							|  |  |  |   }, [handleQuery]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const handleFilterPluginTagsChange = useCallback((tags: string[]) => { | 
					
						
							|  |  |  |     setFilterPluginTags(tags) | 
					
						
							|  |  |  |     filterPluginTagsRef.current = tags | 
					
						
							|  |  |  |     setPage(1) | 
					
						
							|  |  |  |     pageRef.current = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     handleQuery() | 
					
						
							|  |  |  |   }, [handleQuery]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const handleActivePluginTypeChange = useCallback((type: string) => { | 
					
						
							|  |  |  |     setActivePluginType(type) | 
					
						
							|  |  |  |     activePluginTypeRef.current = type | 
					
						
							|  |  |  |     setPage(1) | 
					
						
							|  |  |  |     pageRef.current = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     handleQuery() | 
					
						
							| 
									
										
										
										
											2025-04-10 11:18:43 +08:00
										 |  |  |   }, [handleQuery]) | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const handleSortChange = useCallback((sort: PluginsSort) => { | 
					
						
							|  |  |  |     setSort(sort) | 
					
						
							|  |  |  |     sortRef.current = sort | 
					
						
							|  |  |  |     setPage(1) | 
					
						
							|  |  |  |     pageRef.current = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     handleQueryPlugins() | 
					
						
							|  |  |  |   }, [handleQueryPlugins]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const handlePageChange = useCallback(() => { | 
					
						
							|  |  |  |     if (pluginsTotal && plugins && pluginsTotal > plugins.length) { | 
					
						
							|  |  |  |       setPage(pageRef.current + 1) | 
					
						
							|  |  |  |       pageRef.current++ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       handleQueryPlugins() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }, [handleQueryPlugins, plugins, pluginsTotal]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const handleMoreClick = useCallback((searchParams: SearchParamsFromCollection) => { | 
					
						
							|  |  |  |     setSearchPluginText(searchParams?.query || '') | 
					
						
							|  |  |  |     searchPluginTextRef.current = searchParams?.query || '' | 
					
						
							|  |  |  |     setSort({ | 
					
						
							|  |  |  |       sortBy: searchParams?.sort_by || DEFAULT_SORT.sortBy, | 
					
						
							|  |  |  |       sortOrder: searchParams?.sort_order || DEFAULT_SORT.sortOrder, | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     sortRef.current = { | 
					
						
							|  |  |  |       sortBy: searchParams?.sort_by || DEFAULT_SORT.sortBy, | 
					
						
							|  |  |  |       sortOrder: searchParams?.sort_order || DEFAULT_SORT.sortOrder, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     setPage(1) | 
					
						
							|  |  |  |     pageRef.current = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     handleQueryPlugins() | 
					
						
							|  |  |  |   }, [handleQueryPlugins]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   useMarketplaceContainerScroll(handlePageChange, scrollContainerId) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <MarketplaceContext.Provider | 
					
						
							|  |  |  |       value={{ | 
					
						
							|  |  |  |         intersected, | 
					
						
							|  |  |  |         setIntersected, | 
					
						
							|  |  |  |         searchPluginText, | 
					
						
							|  |  |  |         handleSearchPluginTextChange, | 
					
						
							|  |  |  |         filterPluginTags, | 
					
						
							|  |  |  |         handleFilterPluginTagsChange, | 
					
						
							|  |  |  |         activePluginType, | 
					
						
							|  |  |  |         handleActivePluginTypeChange, | 
					
						
							|  |  |  |         page, | 
					
						
							|  |  |  |         handlePageChange, | 
					
						
							|  |  |  |         plugins, | 
					
						
							|  |  |  |         pluginsTotal, | 
					
						
							|  |  |  |         resetPlugins, | 
					
						
							|  |  |  |         sort, | 
					
						
							|  |  |  |         handleSortChange, | 
					
						
							|  |  |  |         handleQueryPlugins, | 
					
						
							|  |  |  |         handleMoreClick, | 
					
						
							|  |  |  |         marketplaceCollectionsFromClient, | 
					
						
							|  |  |  |         setMarketplaceCollectionsFromClient, | 
					
						
							|  |  |  |         marketplaceCollectionPluginsMapFromClient, | 
					
						
							|  |  |  |         setMarketplaceCollectionPluginsMapFromClient, | 
					
						
							|  |  |  |         isLoading: isLoading || isPluginsLoading, | 
					
						
							|  |  |  |         isSuccessCollections, | 
					
						
							|  |  |  |       }} | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       {children} | 
					
						
							|  |  |  |     </MarketplaceContext.Provider> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } |