fix: marketplace list

pull/12372/head
StyleZhang 2 years ago
parent bca99cf4f8
commit b5be6bacef

@ -1,7 +1,7 @@
import { MarketplaceContextProvider } from './context' import { MarketplaceContextProvider } from './context'
import Description from './description' import Description from './description'
import IntersectionLine from './intersection-line' 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 PluginTypeSwitch from './plugin-type-switch'
import ListWrapper from './list/list-wrapper' import ListWrapper from './list/list-wrapper'
import { getMarketplaceCollectionsAndPlugins } from './utils' import { getMarketplaceCollectionsAndPlugins } from './utils'
@ -18,7 +18,7 @@ const Marketplace = async ({
<MarketplaceContextProvider> <MarketplaceContextProvider>
<Description /> <Description />
<IntersectionLine /> <IntersectionLine />
<SearchBox /> <SearchBoxWrapper />
<PluginTypeSwitch /> <PluginTypeSwitch />
<ListWrapper <ListWrapper
marketplaceCollections={marketplaceCollections} marketplaceCollections={marketplaceCollections}

@ -5,7 +5,20 @@ import TagsFilter from './tags-filter'
import ActionButton from '@/app/components/base/action-button' import ActionButton from '@/app/components/base/action-button'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
const SearchBox = () => { 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 intersected = useMarketplaceContext(v => v.intersected)
const searchPluginText = useMarketplaceContext(v => v.searchPluginText) const searchPluginText = useMarketplaceContext(v => v.searchPluginText)
const handleSearchPluginTextChange = useMarketplaceContext(v => v.handleSearchPluginTextChange) const handleSearchPluginTextChange = useMarketplaceContext(v => v.handleSearchPluginTextChange)
@ -14,18 +27,22 @@ const SearchBox = () => {
<div <div
className={cn( className={cn(
'sticky top-3 flex items-center mx-auto p-1.5 w-[640px] h-11 border border-components-chat-input-border bg-components-panel-bg-blur rounded-xl shadow-md z-[11]', 'sticky top-3 flex items-center mx-auto p-1.5 w-[640px] h-11 border border-components-chat-input-border bg-components-panel-bg-blur rounded-xl shadow-md z-[11]',
inputClassName,
!intersected && 'w-[508px] transition-[width] duration-300', !intersected && 'w-[508px] transition-[width] duration-300',
)} )}
> >
<TagsFilter /> <TagsFilter
tags={tags}
onTagsChange={onTagsChange}
/>
<div className='mx-1 w-[1px] h-3.5 bg-divider-regular'></div> <div className='mx-1 w-[1px] h-3.5 bg-divider-regular'></div>
<div className='grow flex items-center p-1 pl-2'> <div className='grow flex items-center p-1 pl-2'>
<div className='flex items-center mr-2 py-0.5 w-full'> <div className='flex items-center mr-2 py-0.5 w-full'>
<input <input
className='grow block outline-none appearance-none body-md-medium text-text-secondary' className='grow block outline-none appearance-none body-md-medium text-text-secondary'
value={searchPluginText} value={search}
onChange={(e) => { onChange={(e) => {
handleSearchPluginTextChange(e.target.value) onSearchChange(e.target.value)
}} }}
/> />
{ {

@ -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 (
<SearchBox
inputClassName={cn(!intersected && 'w-[508px] transition-[width] duration-300')}
search={searchPluginText}
onSearchChange={handleSearchPluginTextChange}
tags={filterPluginTags}
onTagsChange={handleFilterPluginTagsChange}
/>
)
}
export default SearchBoxWrapper

@ -6,7 +6,6 @@ import {
RiCloseCircleFill, RiCloseCircleFill,
RiFilter3Line, RiFilter3Line,
} from '@remixicon/react' } from '@remixicon/react'
import { useMarketplaceContext } from '../context'
import { import {
PortalToFollowElem, PortalToFollowElem,
PortalToFollowElemContent, PortalToFollowElemContent,
@ -16,9 +15,14 @@ import Checkbox from '@/app/components/base/checkbox'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import Input from '@/app/components/base/input' import Input from '@/app/components/base/input'
const TagsFilter = () => { type TagsFilterProps = {
const filterPluginTags = useMarketplaceContext(v => v.filterPluginTags) tags: string[]
const handleFilterPluginTagsChange = useMarketplaceContext(v => v.handleFilterPluginTagsChange) onTagsChange: (tags: string[]) => void
}
const TagsFilter = ({
tags,
onTagsChange,
}: TagsFilterProps) => {
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const [searchText, setSearchText] = useState('') const [searchText, setSearchText] = useState('')
const options = [ const options = [
@ -33,12 +37,12 @@ const TagsFilter = () => {
] ]
const filteredOptions = options.filter(option => option.text.toLowerCase().includes(searchText.toLowerCase())) const filteredOptions = options.filter(option => option.text.toLowerCase().includes(searchText.toLowerCase()))
const handleCheck = (id: string) => { const handleCheck = (id: string) => {
if (filterPluginTags.includes(id)) if (tags.includes(id))
handleFilterPluginTagsChange(filterPluginTags.filter((tag: string) => tag !== id)) onTagsChange(tags.filter((tag: string) => tag !== id))
else else
handleFilterPluginTagsChange([...filterPluginTags, id]) onTagsChange([...tags, id])
} }
const selectedTagsLength = filterPluginTags.length const selectedTagsLength = tags.length
return ( return (
<PortalToFollowElem <PortalToFollowElem
@ -66,7 +70,7 @@ const TagsFilter = () => {
!selectedTagsLength && 'All Tags' !selectedTagsLength && 'All Tags'
} }
{ {
!!selectedTagsLength && filterPluginTags.slice(0, 2).join(',') !!selectedTagsLength && tags.slice(0, 2).join(',')
} }
{ {
selectedTagsLength > 2 && ( selectedTagsLength > 2 && (
@ -80,7 +84,7 @@ const TagsFilter = () => {
!!selectedTagsLength && ( !!selectedTagsLength && (
<RiCloseCircleFill <RiCloseCircleFill
className='w-4 h-4 text-text-quaternary cursor-pointer' className='w-4 h-4 text-text-quaternary cursor-pointer'
onClick={() => handleFilterPluginTagsChange([])} onClick={() => onTagsChange([])}
/> />
) )
} }
@ -111,7 +115,7 @@ const TagsFilter = () => {
> >
<Checkbox <Checkbox
className='mr-1' className='mr-1'
checked={filterPluginTags.includes(option.value)} checked={tags.includes(option.value)}
/> />
<div className='px-1 system-sm-medium text-text-secondary'> <div className='px-1 system-sm-medium text-text-secondary'>
{option.text} {option.text}

Loading…
Cancel
Save