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.

install-from-marketplace.tsx 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { useCallback, useState } from 'react'
  2. import { useTheme } from 'next-themes'
  3. import { useTranslation } from 'react-i18next'
  4. import Link from 'next/link'
  5. import {
  6. RiArrowDownSLine,
  7. RiArrowRightUpLine,
  8. } from '@remixicon/react'
  9. import type {
  10. ModelProvider,
  11. } from './declarations'
  12. import {
  13. useMarketplaceAllPlugins,
  14. } from './hooks'
  15. import Divider from '@/app/components/base/divider'
  16. import Loading from '@/app/components/base/loading'
  17. import ProviderCard from '@/app/components/plugins/provider-card'
  18. import List from '@/app/components/plugins/marketplace/list'
  19. import type { Plugin } from '@/app/components/plugins/types'
  20. import cn from '@/utils/classnames'
  21. import { getLocaleOnClient } from '@/i18n-config'
  22. import { getMarketplaceUrl } from '@/utils/var'
  23. type InstallFromMarketplaceProps = {
  24. providers: ModelProvider[]
  25. searchText: string
  26. }
  27. const InstallFromMarketplace = ({
  28. providers,
  29. searchText,
  30. }: InstallFromMarketplaceProps) => {
  31. const { t } = useTranslation()
  32. const { theme } = useTheme()
  33. const [collapse, setCollapse] = useState(false)
  34. const locale = getLocaleOnClient()
  35. const {
  36. plugins: allPlugins,
  37. isLoading: isAllPluginsLoading,
  38. } = useMarketplaceAllPlugins(providers, searchText)
  39. const cardRender = useCallback((plugin: Plugin) => {
  40. if (plugin.type === 'bundle')
  41. return null
  42. return <ProviderCard key={plugin.plugin_id} payload={plugin} />
  43. }, [])
  44. return (
  45. <div className='mb-2'>
  46. <Divider className='!mt-4 h-px' />
  47. <div className='flex items-center justify-between'>
  48. <div className='system-md-semibold flex cursor-pointer items-center gap-1 text-text-primary' onClick={() => setCollapse(!collapse)}>
  49. <RiArrowDownSLine className={cn('h-4 w-4', collapse && '-rotate-90')} />
  50. {t('common.modelProvider.installProvider')}
  51. </div>
  52. <div className='mb-2 flex items-center pt-2'>
  53. <span className='system-sm-regular pr-1 text-text-tertiary'>{t('common.modelProvider.discoverMore')}</span>
  54. <Link target="_blank" href={getMarketplaceUrl('', { theme })} className='system-sm-medium inline-flex items-center text-text-accent'>
  55. {t('plugin.marketplace.difyMarketplace')}
  56. <RiArrowRightUpLine className='h-4 w-4' />
  57. </Link>
  58. </div>
  59. </div>
  60. {!collapse && isAllPluginsLoading && <Loading type='area' />}
  61. {
  62. !isAllPluginsLoading && !collapse && (
  63. <List
  64. marketplaceCollections={[]}
  65. marketplaceCollectionPluginsMap={{}}
  66. plugins={allPlugins}
  67. showInstallButton
  68. locale={locale}
  69. cardContainerClassName='grid grid-cols-2 gap-2'
  70. cardRender={cardRender}
  71. emptyClassName='h-auto'
  72. />
  73. )
  74. }
  75. </div>
  76. )
  77. }
  78. export default InstallFromMarketplace