feat: pluging loading

pull/19758/head
Joel 11 months ago committed by Junyan Qin
parent dc33b06bdd
commit 2bcaa8e475
No known key found for this signature in database
GPG Key ID: 22FE3AFADC710CEB

@ -12,6 +12,7 @@ import SearchBox from '@/app/components/plugins/marketplace/search-box'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import ToolItem from './tool-item' import ToolItem from './tool-item'
import Loading from '@/app/components/base/loading'
type Props = { type Props = {
trigger: React.ReactNode trigger: React.ReactNode
@ -64,7 +65,7 @@ const ToolPicker: FC<Props> = ({
const [pluginType, setPluginType] = useState(PLUGIN_TYPE_SEARCH_MAP.all) const [pluginType, setPluginType] = useState(PLUGIN_TYPE_SEARCH_MAP.all)
const [query, setQuery] = useState('') const [query, setQuery] = useState('')
const [tags, setTags] = useState<string[]>([]) const [tags, setTags] = useState<string[]>([])
const { data } = useFetchPluginListOrBundleList({ const { data, isLoading } = useFetchPluginListOrBundleList({
query, query,
tags, tags,
category: pluginType, category: pluginType,
@ -79,6 +80,26 @@ const ToolPicker: FC<Props> = ({
onChange(newValue) onChange(newValue)
} }
}, [onChange, value]) }, [onChange, value])
const listContent = (
<div className='max-h-[396px] overflow-y-auto'>
{list.map(item => (
<ToolItem
key={item.plugin_id}
payload={item}
isChecked={value.includes(item.plugin_id)}
onCheckChange={handleCheckChange(item.plugin_id)}
/>
))}
</div>
)
const loadingContent = (
<div className='flex h-[396px] items-center justify-center'>
<Loading />
</div>
)
return ( return (
<PortalToFollowElem <PortalToFollowElem
placement='top' placement='top'
@ -123,21 +144,12 @@ const ToolPicker: FC<Props> = ({
} }
</div> </div>
</div> </div>
{list.length > 0 && ( {!isLoading && list.length > 0 && listContent}
<div className='max-h-[396px] overflow-y-auto'> {isLoading && loadingContent}
{list.map(item => (
<ToolItem
key={item.plugin_id}
payload={item}
isChecked={value.includes(item.plugin_id)}
onCheckChange={handleCheckChange(item.plugin_id)}
/>
))}
</div>
)}
</div> </div>
</PortalToFollowElemContent> </PortalToFollowElemContent>
</PortalToFollowElem> </PortalToFollowElem>
) )
} }
export default React.memo(ToolPicker) export default React.memo(ToolPicker)

Loading…
Cancel
Save