loaded-item.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. type Props = {
  12. checked: boolean
  13. onCheckedChange: (plugin: Plugin) => void
  14. payload: Plugin
  15. isFromMarketPlace?: boolean
  16. versionInfo: VersionProps
  17. }
  18. const LoadedItem: FC<Props> = ({
  19. checked,
  20. onCheckedChange,
  21. payload,
  22. isFromMarketPlace,
  23. versionInfo: particleVersionInfo,
  24. }) => {
  25. const { getIconUrl } = useGetIcon()
  26. const versionInfo = {
  27. ...particleVersionInfo,
  28. toInstallVersion: payload.version,
  29. }
  30. return (
  31. <div className='flex items-center space-x-2'>
  32. <Checkbox
  33. className='shrink-0'
  34. checked={checked}
  35. onCheck={() => onCheckedChange(payload)}
  36. />
  37. <Card
  38. className='grow'
  39. payload={{
  40. ...payload,
  41. icon: isFromMarketPlace ? `${MARKETPLACE_API_PREFIX}/plugins/${payload.org}/${payload.name}/icon` : getIconUrl(payload.icon),
  42. }}
  43. titleLeft={payload.version ? <Version {...versionInfo} /> : null}
  44. />
  45. </div>
  46. )
  47. }
  48. export default React.memo(LoadedItem)