fix: tool list

This commit is contained in:
StyleZhang 2024-10-31 15:41:02 +08:00
parent 4adb61d6c7
commit 8af8a0f46d
4 changed files with 61 additions and 11 deletions

View File

@ -9,7 +9,7 @@ const Line = ({
<path d="M1 0.5L1 240.5" stroke="url(#paint0_linear_1989_74474)"/> <path d="M1 0.5L1 240.5" stroke="url(#paint0_linear_1989_74474)"/>
<defs> <defs>
<linearGradient id="paint0_linear_1989_74474" x1="-7.99584" y1="240.5" x2="-7.88094" y2="0.50004" gradientUnits="userSpaceOnUse"> <linearGradient id="paint0_linear_1989_74474" x1="-7.99584" y1="240.5" x2="-7.88094" y2="0.50004" gradientUnits="userSpaceOnUse">
<stop stop-color="white" stopOpacity="0.01"/> <stop stopColor="white" stopOpacity="0.01"/>
<stop offset="0.503965" stopColor="#101828" stopOpacity="0.08"/> <stop offset="0.503965" stopColor="#101828" stopOpacity="0.08"/>
<stop offset="1" stopColor="white" stopOpacity="0.01"/> <stop offset="1" stopColor="white" stopOpacity="0.01"/>
</linearGradient> </linearGradient>

View File

@ -3,28 +3,68 @@ import {
useEffect, useEffect,
useState, useState,
} from 'react' } from 'react'
import { useDebounceFn } from 'ahooks'
import type { Plugin } from '@/app/components/plugins/types' import type { Plugin } from '@/app/components/plugins/types'
import type { MarketplaceCollection } from '@/app/components/plugins/marketplace/types' import type {
import { getMarketplaceCollectionsAndPlugins } from '@/app/components/plugins/marketplace/utils' MarketplaceCollection,
PluginsSearchParams,
} from '@/app/components/plugins/marketplace/types'
import {
getMarketplaceCollectionsAndPlugins,
getMarketplacePlugins,
} from '@/app/components/plugins/marketplace/utils'
export const useMarketplace = () => { export const useMarketplace = (searchPluginText: string, filterPluginTags: string[]) => {
const [marketplaceCollections, setMarketplaceCollections] = useState<MarketplaceCollection[]>([]) const [marketplaceCollections, setMarketplaceCollections] = useState<MarketplaceCollection[]>([])
const [marketplaceCollectionPluginsMap, setMarketplaceCollectionPluginsMap] = useState<Record<string, Plugin[]>>({}) const [marketplaceCollectionPluginsMap, setMarketplaceCollectionPluginsMap] = useState<Record<string, Plugin[]>>({})
const [isLoading, setIsLoading] = useState(true) const [isLoading, setIsLoading] = useState(true)
const getMarketplaceCollections = useCallback(async () => { const [plugins, setPlugins] = useState<Plugin[]>()
const handleUpldateMarketplaceCollections = useCallback(async () => {
setIsLoading(true) setIsLoading(true)
const { marketplaceCollections, marketplaceCollectionPluginsMap } = await getMarketplaceCollectionsAndPlugins() const { marketplaceCollections, marketplaceCollectionPluginsMap } = await getMarketplaceCollectionsAndPlugins()
setIsLoading(false) setIsLoading(false)
setMarketplaceCollections(marketplaceCollections) setMarketplaceCollections(marketplaceCollections)
setMarketplaceCollectionPluginsMap(marketplaceCollectionPluginsMap) setMarketplaceCollectionPluginsMap(marketplaceCollectionPluginsMap)
setPlugins(undefined)
}, []) }, [])
const handleUpdatePlugins = async (query: PluginsSearchParams) => {
setIsLoading(true)
const { marketplacePlugins } = await getMarketplacePlugins(query)
setIsLoading(false)
setPlugins(marketplacePlugins)
}
const { run: handleUpdatePluginsWithDebounced } = useDebounceFn(handleUpdatePlugins, {
wait: 500,
})
useEffect(() => { useEffect(() => {
getMarketplaceCollections() if (searchPluginText || filterPluginTags.length) {
}, [getMarketplaceCollections]) if (searchPluginText) {
handleUpdatePluginsWithDebounced({
query: searchPluginText,
tags: filterPluginTags,
})
return
}
handleUpdatePlugins({
query: searchPluginText,
tags: filterPluginTags,
})
}
else {
handleUpldateMarketplaceCollections()
}
}, [searchPluginText, filterPluginTags, handleUpdatePluginsWithDebounced, handleUpldateMarketplaceCollections])
return { return {
isLoading, isLoading,
marketplaceCollections, marketplaceCollections,
marketplaceCollectionPluginsMap, marketplaceCollectionPluginsMap,
plugins,
} }
} }

View File

@ -4,16 +4,21 @@ import List from '@/app/components/plugins/marketplace/list'
import Loading from '@/app/components/base/loading' import Loading from '@/app/components/base/loading'
type MarketplaceProps = { type MarketplaceProps = {
searchPluginText: string
filterPluginTags: string[]
onMarketplaceScroll: () => void onMarketplaceScroll: () => void
} }
const Marketplace = ({ const Marketplace = ({
searchPluginText,
filterPluginTags,
onMarketplaceScroll, onMarketplaceScroll,
}: MarketplaceProps) => { }: MarketplaceProps) => {
const { const {
isLoading, isLoading,
marketplaceCollections, marketplaceCollections,
marketplaceCollectionPluginsMap, marketplaceCollectionPluginsMap,
} = useMarketplace() plugins,
} = useMarketplace(searchPluginText, filterPluginTags)
return ( return (
<div className='shrink-0 sticky -bottom-[442px] h-[530px] overflow-y-auto px-12 py-2 pt-0 bg-background-default-subtle'> <div className='shrink-0 sticky -bottom-[442px] h-[530px] overflow-y-auto px-12 py-2 pt-0 bg-background-default-subtle'>
@ -55,6 +60,7 @@ const Marketplace = ({
<List <List
marketplaceCollections={marketplaceCollections} marketplaceCollections={marketplaceCollections}
marketplaceCollectionPluginsMap={marketplaceCollectionPluginsMap} marketplaceCollectionPluginsMap={marketplaceCollectionPluginsMap}
plugins={plugins}
showInstallButton showInstallButton
/> />
) )

View File

@ -126,9 +126,13 @@ const ProviderList = () => {
</div> </div>
{ {
enable_marketplace && ( enable_marketplace && (
<Marketplace onMarketplaceScroll={() => { <Marketplace
onMarketplaceScroll={() => {
containerRef.current?.scrollTo({ top: containerRef.current.scrollHeight, behavior: 'smooth' }) containerRef.current?.scrollTo({ top: containerRef.current.scrollHeight, behavior: 'smooth' })
}} /> }}
searchPluginText={keywords}
filterPluginTags={tagFilterValue}
/>
) )
} }
</div> </div>