import React, { useMemo, useRef, useState } from 'react' import { MagicBox } from '@/app/components/base/icons/src/vender/solid/mediaAndDevices' import { FileZip } from '@/app/components/base/icons/src/vender/solid/files' import { Github } from '@/app/components/base/icons/src/vender/solid/general' import InstallFromGitHub from '@/app/components/plugins/install-plugin/install-from-github' import InstallFromLocalPackage from '@/app/components/plugins/install-plugin/install-from-local-package' import { usePluginPageContext } from '../context' import type { PluginDetail } from '../../types' import { Group } from '@/app/components/base/icons/src/vender/other' import { useSelector as useAppContextSelector } from '@/context/app-context' import Line from '../../marketplace/empty/line' const Empty = () => { const fileInputRef = useRef(null) const [selectedAction, setSelectedAction] = useState(null) const [selectedFile, setSelectedFile] = useState(null) const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures) const setActiveTab = usePluginPageContext(v => v.setActiveTab) const handleFileChange = (event: React.ChangeEvent) => { const file = event.target.files?.[0] if (file) { setSelectedFile(file) setSelectedAction('local') } } const filters = usePluginPageContext(v => v.filters) const pluginList = usePluginPageContext(v => v.installedPluginList) as PluginDetail[] const text = useMemo(() => { if (pluginList.length === 0) return 'No plugins installed' if (filters.categories.length > 0 || filters.tags.length > 0 || filters.searchQuery) return 'No plugins found' }, [pluginList.length, filters]) return (
{/* skeleton */}
{Array.from({ length: 20 }).fill(0).map((_, i) => (
))}
{/* mask */}
{text}
{[ ...( (enable_marketplace || true) ? [{ icon: MagicBox, text: 'Marketplace', action: 'marketplace' }] : [] ), { icon: Github, text: 'GitHub', action: 'github' }, { icon: FileZip, text: 'Local Package File', action: 'local' }, ].map(({ icon: Icon, text, action }) => (
{ if (action === 'local') fileInputRef.current?.click() else if (action === 'marketplace') setActiveTab('discover') else setSelectedAction(action) }} > {`Install from ${text}`}
))}
{selectedAction === 'github' && setSelectedAction(null)} />} {selectedAction === 'local' && selectedFile && ( setSelectedAction(null)} onSuccess={() => { }} /> ) }
) } Empty.displayName = 'Empty' export default React.memo(Empty)