- Notifications
You must be signed in to change notification settings - Fork 20.9k
refactor: marketplace state management #30702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
63 commits Select commit Hold shift + click to select a range
58550a5 refactor: replace marketplace context with nuqs + jotai + tanstack query
hyoban 64909f1 no test change for now
hyoban e529368 tab
hyoban 3b4e6bd Merge branch 'main' into 1-7-marketplace-state
hyoban 712c2c1 reative version
hyoban 75fddd8 Merge branch 'main' into 1-7-marketplace-state
hyoban 38d5f22 update
hyoban afec4f7 update
hyoban 060c480 update
hyoban 8feb878 update
hyoban 10a4d7b update
hyoban 98aff7e update
hyoban a7402ac Merge branch 'main' into 1-7-marketplace-state
hyoban 2ba0adb update
hyoban 8acd17d update
hyoban ee8f6c2 update
hyoban 21c647b update
hyoban 5614fc8 update
hyoban 5ab08b1 search mode
hyoban 0ded496 search mode default
hyoban 7b05cc1 better search mode logic
hyoban 38507d8 prefetch
hyoban 8549f51 prefetch for all category
hyoban 385d3fc share params
hyoban 817ed91 no prefetch for app
hyoban f47ff73 type
hyoban e55640f rename
hyoban 237ee02 rename
hyoban 9a80174 update
hyoban 1b7d182 update
hyoban e509a9b update
hyoban bd73c33 update
hyoban a63d985 note
hyoban e04a45b parseAsStringEnum
hyoban df183b7 upda
hyoban 908d649 value of
hyoban ff97344 update
hyoban 16b7ae9 deprecated
hyoban d91306d Merge branch 'main' into 1-7-marketplace-state
hyoban 200b028 update
hyoban 3d2950e update
hyoban 0f46207 update
hyoban 147d6e4 update
hyoban effdcf9 update
hyoban 2f0cafb update
hyoban d04a8dd update
hyoban 3d356d9 update
hyoban 15cdafc update
hyoban 0115251 update
hyoban cfb7e8f update
hyoban fe24859 update
hyoban 369b982 update
hyoban b8955c6 deprecated only
hyoban 53af2ff todo
hyoban 18853eb fix: remove obsolete context-based tests and fix type errors
hyoban e500dc7 Merge branch 'main' into 1-7-marketplace-state
hyoban 77c531b no preserve in app
hyoban b95129c refactor
hyoban 12e496d fix test
hyoban c2cb75f rename
hyoban 3592093 bring back debounce
hyoban aecee0c debounce text only
hyoban a85c811 fix load next page
hyoban File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import type { ActivePluginType } from './constants' | ||
| import type { PluginsSort, SearchParamsFromCollection } from './types' | ||
| import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai' | ||
| import { useQueryState } from 'nuqs' | ||
| import { useCallback } from 'react' | ||
| import { DEFAULT_SORT, PLUGIN_CATEGORY_WITH_COLLECTIONS } from './constants' | ||
| import { marketplaceSearchParamsParsers } from './search-params' | ||
| | ||
| const marketplaceSortAtom = atom<PluginsSort>(DEFAULT_SORT) | ||
| export function useMarketplaceSort() { | ||
| return useAtom(marketplaceSortAtom) | ||
| } | ||
| export function useMarketplaceSortValue() { | ||
| return useAtomValue(marketplaceSortAtom) | ||
| } | ||
| export function useSetMarketplaceSort() { | ||
| return useSetAtom(marketplaceSortAtom) | ||
| } | ||
| | ||
| /** | ||
| * Preserve the state for marketplace | ||
| */ | ||
| export const preserveSearchStateInQueryAtom = atom<boolean>(false) | ||
| | ||
| const searchPluginTextAtom = atom<string>('') | ||
| const activePluginTypeAtom = atom<ActivePluginType>('all') | ||
| const filterPluginTagsAtom = atom<string[]>([]) | ||
| | ||
| export function useSearchPluginText() { | ||
| const preserveSearchStateInQuery = useAtomValue(preserveSearchStateInQueryAtom) | ||
| const queryState = useQueryState('q', marketplaceSearchParamsParsers.q) | ||
| const atomState = useAtom(searchPluginTextAtom) | ||
| return preserveSearchStateInQuery ? queryState : atomState | ||
| } | ||
| export function useActivePluginType() { | ||
| const preserveSearchStateInQuery = useAtomValue(preserveSearchStateInQueryAtom) | ||
| const queryState = useQueryState('category', marketplaceSearchParamsParsers.category) | ||
| const atomState = useAtom(activePluginTypeAtom) | ||
| return preserveSearchStateInQuery ? queryState : atomState | ||
| } | ||
| export function useFilterPluginTags() { | ||
| const preserveSearchStateInQuery = useAtomValue(preserveSearchStateInQueryAtom) | ||
| const queryState = useQueryState('tags', marketplaceSearchParamsParsers.tags) | ||
| const atomState = useAtom(filterPluginTagsAtom) | ||
| return preserveSearchStateInQuery ? queryState : atomState | ||
| } | ||
| | ||
| /** | ||
| * Not all categories have collections, so we need to | ||
| * force the search mode for those categories. | ||
| */ | ||
| export const searchModeAtom = atom<true | null>(null) | ||
| | ||
| export function useMarketplaceSearchMode() { | ||
| const [searchPluginText] = useSearchPluginText() | ||
| const [filterPluginTags] = useFilterPluginTags() | ||
| const [activePluginType] = useActivePluginType() | ||
| | ||
| const searchMode = useAtomValue(searchModeAtom) | ||
| const isSearchMode = !!searchPluginText | ||
| || filterPluginTags.length > 0 | ||
| || (searchMode ?? (!PLUGIN_CATEGORY_WITH_COLLECTIONS.has(activePluginType))) | ||
| return isSearchMode | ||
| } | ||
hyoban marked this conversation as resolved. Show resolved Hide resolved | ||
| | ||
| export function useMarketplaceMoreClick() { | ||
| const [,setQ] = useSearchPluginText() | ||
| const setSort = useSetAtom(marketplaceSortAtom) | ||
| const setSearchMode = useSetAtom(searchModeAtom) | ||
| | ||
| return useCallback((searchParams?: SearchParamsFromCollection) => { | ||
| if (!searchParams) | ||
| return | ||
| setQ(searchParams?.query || '') | ||
| setSort({ | ||
| sortBy: searchParams?.sort_by || DEFAULT_SORT.sortBy, | ||
| sortOrder: searchParams?.sort_order || DEFAULT_SORT.sortOrder, | ||
| }) | ||
| setSearchMode(true) | ||
| }, [setQ, setSort, setSearchMode]) | ||
hyoban marked this conversation as resolved. Show resolved Hide resolved | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,30 @@ | ||
| import { PluginCategoryEnum } from '../types' | ||
| | ||
| export const DEFAULT_SORT = { | ||
| sortBy: 'install_count', | ||
| sortOrder: 'DESC', | ||
| } | ||
| | ||
| export const SCROLL_BOTTOM_THRESHOLD = 100 | ||
| | ||
| export const PLUGIN_TYPE_SEARCH_MAP = { | ||
| all: 'all', | ||
| model: PluginCategoryEnum.model, | ||
| tool: PluginCategoryEnum.tool, | ||
| agent: PluginCategoryEnum.agent, | ||
| extension: PluginCategoryEnum.extension, | ||
| datasource: PluginCategoryEnum.datasource, | ||
| trigger: PluginCategoryEnum.trigger, | ||
| bundle: 'bundle', | ||
| } as const | ||
| | ||
| type ValueOf<T> = T[keyof T] | ||
| | ||
| export type ActivePluginType = ValueOf<typeof PLUGIN_TYPE_SEARCH_MAP> | ||
| | ||
| export const PLUGIN_CATEGORY_WITH_COLLECTIONS = new Set<ActivePluginType>( | ||
| [ | ||
| PLUGIN_TYPE_SEARCH_MAP.all, | ||
| PLUGIN_TYPE_SEARCH_MAP.tool, | ||
| ], | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.