Skip to content

Commit c98870c

Browse files
byteforge38hyoban
andauthored
refactor: always preserve marketplace search state in URL (langgenius#31069)
Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com>
1 parent b06c7c8 commit c98870c

File tree

4 files changed

+12
-50
lines changed

4 files changed

+12
-50
lines changed

web/app/components/plugins/marketplace/atoms.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { ActivePluginType } from './constants'
21
import type { PluginsSort, SearchParamsFromCollection } from './types'
32
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai'
43
import { useQueryState } from 'nuqs'
@@ -17,32 +16,14 @@ export function useSetMarketplaceSort() {
1716
return useSetAtom(marketplaceSortAtom)
1817
}
1918

20-
/**
21-
* Preserve the state for marketplace
22-
*/
23-
export const preserveSearchStateInQueryAtom = atom<boolean>(false)
24-
25-
const searchPluginTextAtom = atom<string>('')
26-
const activePluginTypeAtom = atom<ActivePluginType>('all')
27-
const filterPluginTagsAtom = atom<string[]>([])
28-
2919
export function useSearchPluginText() {
30-
const preserveSearchStateInQuery = useAtomValue(preserveSearchStateInQueryAtom)
31-
const queryState = useQueryState('q', marketplaceSearchParamsParsers.q)
32-
const atomState = useAtom(searchPluginTextAtom)
33-
return preserveSearchStateInQuery ? queryState : atomState
20+
return useQueryState('q', marketplaceSearchParamsParsers.q)
3421
}
3522
export function useActivePluginType() {
36-
const preserveSearchStateInQuery = useAtomValue(preserveSearchStateInQueryAtom)
37-
const queryState = useQueryState('category', marketplaceSearchParamsParsers.category)
38-
const atomState = useAtom(activePluginTypeAtom)
39-
return preserveSearchStateInQuery ? queryState : atomState
23+
return useQueryState('category', marketplaceSearchParamsParsers.category)
4024
}
4125
export function useFilterPluginTags() {
42-
const preserveSearchStateInQuery = useAtomValue(preserveSearchStateInQueryAtom)
43-
const queryState = useQueryState('tags', marketplaceSearchParamsParsers.tags)
44-
const atomState = useAtom(filterPluginTagsAtom)
45-
return preserveSearchStateInQuery ? queryState : atomState
26+
return useQueryState('tags', marketplaceSearchParamsParsers.tags)
4627
}
4728

4829
/**

web/app/components/plugins/marketplace/hydration-client.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

web/app/components/plugins/marketplace/index.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { SearchParams } from 'nuqs'
22
import { TanstackQueryInitializer } from '@/context/query-client'
33
import Description from './description'
4-
import { HydrateMarketplaceAtoms } from './hydration-client'
54
import { HydrateQueryClient } from './hydration-server'
65
import ListWrapper from './list/list-wrapper'
76
import StickySearchAndSwitchWrapper from './sticky-search-and-switch-wrapper'
@@ -10,8 +9,7 @@ type MarketplaceProps = {
109
showInstallButton?: boolean
1110
pluginTypeSwitchClassName?: string
1211
/**
13-
* Pass the search params from the request to prefetch data on the server
14-
* and preserve the search params in the URL.
12+
* Pass the search params from the request to prefetch data on the server.
1513
*/
1614
searchParams?: Promise<SearchParams>
1715
}
@@ -24,15 +22,13 @@ const Marketplace = async ({
2422
return (
2523
<TanstackQueryInitializer>
2624
<HydrateQueryClient searchParams={searchParams}>
27-
<HydrateMarketplaceAtoms preserveSearchStateInQuery={!!searchParams}>
28-
<Description />
29-
<StickySearchAndSwitchWrapper
30-
pluginTypeSwitchClassName={pluginTypeSwitchClassName}
31-
/>
32-
<ListWrapper
33-
showInstallButton={showInstallButton}
34-
/>
35-
</HydrateMarketplaceAtoms>
25+
<Description />
26+
<StickySearchAndSwitchWrapper
27+
pluginTypeSwitchClassName={pluginTypeSwitchClassName}
28+
/>
29+
<ListWrapper
30+
showInstallButton={showInstallButton}
31+
/>
3632
</HydrateQueryClient>
3733
</TanstackQueryInitializer>
3834
)

web/app/components/plugins/plugin-page/context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const PluginPageContextProvider = ({
6868
const options = useMemo(() => {
6969
return enable_marketplace ? tabs : tabs.filter(tab => tab.value !== PLUGIN_PAGE_TABS_MAP.marketplace)
7070
}, [tabs, enable_marketplace])
71-
const [activeTab, setActiveTab] = useQueryState('category', {
71+
const [activeTab, setActiveTab] = useQueryState('tab', {
7272
defaultValue: options[0].value,
7373
})
7474

0 commit comments

Comments
 (0)