diff --git a/web/app/components/plugins/marketplace/index.tsx b/web/app/components/plugins/marketplace/index.tsx index d9f0920893..0c87cce924 100644 --- a/web/app/components/plugins/marketplace/index.tsx +++ b/web/app/components/plugins/marketplace/index.tsx @@ -1,7 +1,7 @@ import { MarketplaceContextProvider } from './context' import Description from './description' import IntersectionLine from './intersection-line' -import SearchBox from './search-box' +import SearchBoxWrapper from './search-box/search-box-wrapper' import PluginTypeSwitch from './plugin-type-switch' import ListWrapper from './list/list-wrapper' import { getMarketplaceCollectionsAndPlugins } from './utils' @@ -18,7 +18,7 @@ const Marketplace = async ({ - + { +type SearchBoxProps = { + search: string + onSearchChange: (search: string) => void + inputClassName?: string + tags: string[] + onTagsChange: (tags: string[]) => void +} +const SearchBox = ({ + search, + onSearchChange, + inputClassName, + tags, + onTagsChange, +}: SearchBoxProps) => { const intersected = useMarketplaceContext(v => v.intersected) const searchPluginText = useMarketplaceContext(v => v.searchPluginText) const handleSearchPluginTextChange = useMarketplaceContext(v => v.handleSearchPluginTextChange) @@ -14,18 +27,22 @@ const SearchBox = () => {
- +
{ - handleSearchPluginTextChange(e.target.value) + onSearchChange(e.target.value) }} /> { diff --git a/web/app/components/plugins/marketplace/search-box/search-box-wrapper.tsx b/web/app/components/plugins/marketplace/search-box/search-box-wrapper.tsx new file mode 100644 index 0000000000..0758d7785b --- /dev/null +++ b/web/app/components/plugins/marketplace/search-box/search-box-wrapper.tsx @@ -0,0 +1,24 @@ +'use client' +import { useMarketplaceContext } from '../context' +import SearchBox from './index' +import cn from '@/utils/classnames' + +const SearchBoxWrapper = () => { + const intersected = useMarketplaceContext(v => v.intersected) + const searchPluginText = useMarketplaceContext(v => v.searchPluginText) + const handleSearchPluginTextChange = useMarketplaceContext(v => v.handleSearchPluginTextChange) + const filterPluginTags = useMarketplaceContext(v => v.filterPluginTags) + const handleFilterPluginTagsChange = useMarketplaceContext(v => v.handleFilterPluginTagsChange) + + return ( + + ) +} + +export default SearchBoxWrapper diff --git a/web/app/components/plugins/marketplace/search-box/tags-filter.tsx b/web/app/components/plugins/marketplace/search-box/tags-filter.tsx index 95d806c43b..51746fddb4 100644 --- a/web/app/components/plugins/marketplace/search-box/tags-filter.tsx +++ b/web/app/components/plugins/marketplace/search-box/tags-filter.tsx @@ -6,7 +6,6 @@ import { RiCloseCircleFill, RiFilter3Line, } from '@remixicon/react' -import { useMarketplaceContext } from '../context' import { PortalToFollowElem, PortalToFollowElemContent, @@ -16,9 +15,14 @@ import Checkbox from '@/app/components/base/checkbox' import cn from '@/utils/classnames' import Input from '@/app/components/base/input' -const TagsFilter = () => { - const filterPluginTags = useMarketplaceContext(v => v.filterPluginTags) - const handleFilterPluginTagsChange = useMarketplaceContext(v => v.handleFilterPluginTagsChange) +type TagsFilterProps = { + tags: string[] + onTagsChange: (tags: string[]) => void +} +const TagsFilter = ({ + tags, + onTagsChange, +}: TagsFilterProps) => { const [open, setOpen] = useState(false) const [searchText, setSearchText] = useState('') const options = [ @@ -33,12 +37,12 @@ const TagsFilter = () => { ] const filteredOptions = options.filter(option => option.text.toLowerCase().includes(searchText.toLowerCase())) const handleCheck = (id: string) => { - if (filterPluginTags.includes(id)) - handleFilterPluginTagsChange(filterPluginTags.filter((tag: string) => tag !== id)) + if (tags.includes(id)) + onTagsChange(tags.filter((tag: string) => tag !== id)) else - handleFilterPluginTagsChange([...filterPluginTags, id]) + onTagsChange([...tags, id]) } - const selectedTagsLength = filterPluginTags.length + const selectedTagsLength = tags.length return ( { !selectedTagsLength && 'All Tags' } { - !!selectedTagsLength && filterPluginTags.slice(0, 2).join(',') + !!selectedTagsLength && tags.slice(0, 2).join(',') } { selectedTagsLength > 2 && ( @@ -80,7 +84,7 @@ const TagsFilter = () => { !!selectedTagsLength && ( handleFilterPluginTagsChange([])} + onClick={() => onTagsChange([])} /> ) } @@ -111,7 +115,7 @@ const TagsFilter = () => { >
{option.text}