import { Avatar } from 'tailchat-design'; import { Button, Space } from 'antd'; import React, { useCallback, useState } from 'react'; import { isValidStr, parseUrlStr, PluginManifest, showAlert, showToasts, t, useAsyncRequest, } from 'tailchat-shared'; import { ModalWrapper, openModal } from '../common'; import { pluginManager } from '../manager'; import { DocumentView } from './DocumentView'; import { getManifestFieldWithI18N } from '../utils'; /** * 插件项 */ export const PluginStoreItem: React.FC<{ manifest: PluginManifest; installed: boolean; builtin?: boolean; }> = React.memo((props) => { const { manifest, builtin = false } = props; const [installed, setInstalled] = useState(props.installed); const [{ loading }, handleInstallPlugin] = useAsyncRequest(async () => { await pluginManager.installPlugin(manifest); if (manifest.requireRestart === true) { showToasts(t('插件安装成功, 刷新页面后生效'), 'success'); } else { showToasts(t('插件安装成功'), 'success'); } setInstalled(true); }, [manifest]); const handleUninstallPlugin = useCallback(() => { showAlert({ message: t('是否要卸载插件'), onConfirm: async () => { await pluginManager.uninstallPlugin(manifest.name); showToasts(t('插件卸载成功, 刷新页面后生效'), 'success'); }, }); }, [manifest]); const handleShowDocument = useCallback(() => { if (!isValidStr(manifest.documentUrl)) { return; } openModal( ); }, [manifest]); const label = getManifestFieldWithI18N(manifest, 'label'); const description = getManifestFieldWithI18N(manifest, 'description'); return (
{label}
{manifest.name}
{description}
{isValidStr(manifest.documentUrl) && ( )}
{builtin ? ( ) : installed ? ( ) : ( )}
); }); PluginStoreItem.displayName = 'PluginStoreItem';