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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import React, { useMemo, useRef, useState } from 'react'
  2. import { MagicBox } from '@/app/components/base/icons/src/vender/solid/mediaAndDevices'
  3. import { FileZip } from '@/app/components/base/icons/src/vender/solid/files'
  4. import { Github } from '@/app/components/base/icons/src/vender/solid/general'
  5. import InstallFromGitHub from '@/app/components/plugins/install-plugin/install-from-github'
  6. import InstallFromLocalPackage from '@/app/components/plugins/install-plugin/install-from-local-package'
  7. import { usePluginPageContext } from '../context'
  8. import { Group } from '@/app/components/base/icons/src/vender/other'
  9. import Line from '../../marketplace/empty/line'
  10. import { useInstalledPluginList } from '@/service/use-plugins'
  11. import { useTranslation } from 'react-i18next'
  12. import { SUPPORT_INSTALL_LOCAL_FILE_EXTENSIONS } from '@/config'
  13. import { noop } from 'lodash-es'
  14. import { useGlobalPublicStore } from '@/context/global-public-context'
  15. const Empty = () => {
  16. const { t } = useTranslation()
  17. const fileInputRef = useRef<HTMLInputElement>(null)
  18. const [selectedAction, setSelectedAction] = useState<string | null>(null)
  19. const [selectedFile, setSelectedFile] = useState<File | null>(null)
  20. const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures)
  21. const setActiveTab = usePluginPageContext(v => v.setActiveTab)
  22. const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
  23. const file = event.target.files?.[0]
  24. if (file) {
  25. setSelectedFile(file)
  26. setSelectedAction('local')
  27. }
  28. }
  29. const filters = usePluginPageContext(v => v.filters)
  30. const { data: pluginList } = useInstalledPluginList()
  31. const text = useMemo(() => {
  32. if (pluginList?.plugins.length === 0)
  33. return t('plugin.list.noInstalled')
  34. if (filters.categories.length > 0 || filters.tags.length > 0 || filters.searchQuery)
  35. return t('plugin.list.notFound')
  36. }, [pluginList?.plugins.length, t, filters.categories.length, filters.tags.length, filters.searchQuery])
  37. return (
  38. <div className='relative z-0 w-full grow'>
  39. {/* skeleton */}
  40. <div className='absolute top-0 z-10 grid h-full w-full grid-cols-2 gap-2 overflow-hidden px-12'>
  41. {Array.from({ length: 20 }).fill(0).map((_, i) => (
  42. <div key={i} className='h-[100px] rounded-xl bg-components-card-bg' />
  43. ))}
  44. </div>
  45. {/* mask */}
  46. <div className='absolute z-20 h-full w-full bg-gradient-to-b from-components-panel-bg-transparent to-components-panel-bg' />
  47. <div className='relative z-30 flex h-full items-center justify-center'>
  48. <div className='flex flex-col items-center gap-y-3'>
  49. <div className='relative -z-10 flex h-[52px] w-[52px] items-center justify-center rounded-xl
  50. border-[1px] border-dashed border-divider-deep bg-components-card-bg shadow-xl shadow-shadow-shadow-5'>
  51. <Group className='h-5 w-5 text-text-tertiary' />
  52. <Line className='absolute right-[-1px] top-1/2 -translate-y-1/2' />
  53. <Line className='absolute left-[-1px] top-1/2 -translate-y-1/2' />
  54. <Line className='absolute left-1/2 top-0 -translate-x-1/2 -translate-y-1/2 rotate-90' />
  55. <Line className='absolute left-1/2 top-full -translate-x-1/2 -translate-y-1/2 rotate-90' />
  56. </div>
  57. <div className='text-sm font-normal text-text-tertiary'>
  58. {text}
  59. </div>
  60. <div className='flex w-[240px] flex-col'>
  61. <input
  62. type='file'
  63. ref={fileInputRef}
  64. style={{ display: 'none' }}
  65. onChange={handleFileChange}
  66. accept={SUPPORT_INSTALL_LOCAL_FILE_EXTENSIONS}
  67. />
  68. <div className='flex w-full flex-col gap-y-1'>
  69. {[
  70. ...(
  71. (enable_marketplace)
  72. ? [{ icon: MagicBox, text: t('plugin.list.source.marketplace'), action: 'marketplace' }]
  73. : []
  74. ),
  75. { icon: Github, text: t('plugin.list.source.github'), action: 'github' },
  76. { icon: FileZip, text: t('plugin.list.source.local'), action: 'local' },
  77. ].map(({ icon: Icon, text, action }) => (
  78. <div
  79. key={action}
  80. className='flex cursor-pointer items-center gap-x-1 rounded-lg border-[0.5px] bg-components-button-secondary-bg
  81. px-3 py-2 shadow-xs shadow-shadow-shadow-3 hover:bg-state-base-hover'
  82. onClick={() => {
  83. if (action === 'local')
  84. fileInputRef.current?.click()
  85. else if (action === 'marketplace')
  86. setActiveTab('discover')
  87. else
  88. setSelectedAction(action)
  89. }}
  90. >
  91. <Icon className="h-4 w-4 text-text-tertiary" />
  92. <span className='system-md-regular text-text-secondary'>{text}</span>
  93. </div>
  94. ))}
  95. </div>
  96. </div>
  97. </div>
  98. {selectedAction === 'github' && <InstallFromGitHub
  99. onSuccess={noop}
  100. onClose={() => setSelectedAction(null)}
  101. />}
  102. {selectedAction === 'local' && selectedFile
  103. && (<InstallFromLocalPackage
  104. file={selectedFile}
  105. onClose={() => setSelectedAction(null)}
  106. onSuccess={noop}
  107. />
  108. )
  109. }
  110. </div>
  111. </div>
  112. )
  113. }
  114. Empty.displayName = 'Empty'
  115. export default React.memo(Empty)