chore: handle uploaded selected

This commit is contained in:
Joel 2024-11-14 18:31:10 +08:00
parent 495d86fd96
commit 6f5e010db5
3 changed files with 10 additions and 12 deletions

View File

@ -27,7 +27,7 @@ const LoadedItem: FC<Props> = ({
<Card
className='grow'
payload={payload}
titleLeft={<Badge className='mx-1' size="s" state={BadgeState.Default}>{payload.version}</Badge>}
titleLeft={payload.version ? <Badge className='mx-1' size="s" state={BadgeState.Default}>{payload.version}</Badge> : null}
/>
</div>
)

View File

@ -65,14 +65,14 @@ const InstallByDSLList: FC<Props> = ({
d.type === 'github'
? <GithubItem
key={index}
checked={!!selectedPlugins.find(p => p.plugin_id === d.value.plugin_unique_identifier)}
checked={!!selectedPlugins.find(p => p.plugin_id === plugins[index]?.plugin_id)}
onCheckedChange={handleSelect}
dependency={d}
onFetchedPayload={handlePlugInFetched(index)}
/>
: <MarketplaceItem
key={index}
checked={!!selectedPlugins.find(p => p.plugin_id === d.value.plugin_unique_identifier)}
checked={!!selectedPlugins.find(p => p.plugin_id === plugins[index]?.plugin_id)}
onCheckedChange={handleSelect}
payload={plugins[index] as Plugin}
/>

View File

@ -23,15 +23,13 @@ const Install: FC<Props> = ({
const selectedPluginsNum = selectedPlugins.length
const handleSelect = (plugin: Plugin) => {
return () => {
const isSelected = !!selectedPlugins.find(p => p.plugin_id === plugin.plugin_id)
let nextSelectedPlugins
if (isSelected)
nextSelectedPlugins = selectedPlugins.filter(p => p.plugin_id !== plugin.plugin_id)
else
nextSelectedPlugins = [...selectedPlugins, plugin]
setSelectedPlugins(nextSelectedPlugins)
}
const isSelected = !!selectedPlugins.find(p => p.plugin_id === plugin.plugin_id)
let nextSelectedPlugins
if (isSelected)
nextSelectedPlugins = selectedPlugins.filter(p => p.plugin_id !== plugin.plugin_id)
else
nextSelectedPlugins = [...selectedPlugins, plugin]
setSelectedPlugins(nextSelectedPlugins)
}
const [canInstall, setCanInstall] = React.useState(false)
const handleLoadedAllPlugin = useCallback(() => {