You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

loaded-item.tsx 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import type { Plugin } from '../../../types'
  5. import Card from '../../../card'
  6. import Checkbox from '@/app/components/base/checkbox'
  7. import useGetIcon from '../../base/use-get-icon'
  8. import { MARKETPLACE_API_PREFIX } from '@/config'
  9. import Version from '../../base/version'
  10. import type { VersionProps } from '../../../types'
  11. import usePluginInstallLimit from '../../hooks/use-install-plugin-limit'
  12. type Props = {
  13. checked: boolean
  14. onCheckedChange: (plugin: Plugin) => void
  15. payload: Plugin
  16. isFromMarketPlace?: boolean
  17. versionInfo: VersionProps
  18. }
  19. const LoadedItem: FC<Props> = ({
  20. checked,
  21. onCheckedChange,
  22. payload,
  23. isFromMarketPlace,
  24. versionInfo: particleVersionInfo,
  25. }) => {
  26. const { getIconUrl } = useGetIcon()
  27. const versionInfo = {
  28. ...particleVersionInfo,
  29. toInstallVersion: payload.version,
  30. }
  31. const { canInstall } = usePluginInstallLimit(payload)
  32. return (
  33. <div className='flex items-center space-x-2'>
  34. <Checkbox
  35. disabled={!canInstall}
  36. className='shrink-0'
  37. checked={checked}
  38. onCheck={() => onCheckedChange(payload)}
  39. />
  40. <Card
  41. className='grow'
  42. payload={{
  43. ...payload,
  44. icon: isFromMarketPlace ? `${MARKETPLACE_API_PREFIX}/plugins/${payload.org}/${payload.name}/icon` : getIconUrl(payload.icon),
  45. }}
  46. titleLeft={payload.version ? <Version {...versionInfo} /> : null}
  47. limitedInstall={!canInstall}
  48. />
  49. </div>
  50. )
  51. }
  52. export default React.memo(LoadedItem)