import { useMemo, useState, } from 'react' import { RiCheckboxCircleFill, RiErrorWarningFill, RiInstallLine, } from '@remixicon/react' import { useTranslation } from 'react-i18next' import { usePluginTaskStatus } from './hooks' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' import Tooltip from '@/app/components/base/tooltip' import Button from '@/app/components/base/button' import ProgressCircle from '@/app/components/base/progress-bar/progress-circle' import CardIcon from '@/app/components/plugins/card/base/card-icon' import cn from '@/utils/classnames' import { useGetLanguage } from '@/context/i18n' import useGetIcon from '@/app/components/plugins/install-plugin/base/use-get-icon' const PluginTasks = () => { const { t } = useTranslation() const language = useGetLanguage() const [open, setOpen] = useState(false) const { errorPlugins, runningPlugins, successPlugins, totalPluginsLength, handleClearErrorPlugin, } = usePluginTaskStatus() const { getIconUrl } = useGetIcon() const isInstalling = runningPlugins.length > 0 && errorPlugins.length === 0 && successPlugins.length === 0 const isInstallingWithError = errorPlugins.length > 0 && errorPlugins.length < totalPluginsLength const isSuccess = successPlugins.length === totalPluginsLength && totalPluginsLength > 0 const isFailed = errorPlugins.length === totalPluginsLength && totalPluginsLength > 0 const tip = useMemo(() => { if (isInstalling) return t('plugin.task.installing', { installingLength: runningPlugins.length, totalLength: totalPluginsLength }) if (isInstallingWithError) return t('plugin.task.installingWithError', { installingLength: runningPlugins.length, totalLength: totalPluginsLength, errorLength: errorPlugins.length }) if (isFailed) return t('plugin.task.installError', { errorLength: errorPlugins.length }) }, [isInstalling, isInstallingWithError, isFailed, errorPlugins, runningPlugins, totalPluginsLength, t]) return (
{ if (isFailed || isInstallingWithError) setOpen(v => !v) }} >
{ isInstalling && ( ) } { isInstallingWithError && ( ) } { isSuccess && ( ) } { isFailed && ( ) }
{t('plugin.task.installedError')}
{ errorPlugins.map(errorPlugin => (
{errorPlugin.labels[language]}
)) }
) } export default PluginTasks