'use client' import React from 'react' import Button from '@/app/components/base/button' import type { PluginDeclaration, UpdateFromGitHubPayload } from '../../../types' import Card from '../../../card' import Badge, { BadgeState } from '@/app/components/base/badge/index' import { pluginManifestToCardPluginProps } from '../../utils' import { useTranslation } from 'react-i18next' import { installPackageFromGitHub, uninstallPlugin } from '@/service/plugins' import { RiLoader2Line } from '@remixicon/react' import { usePluginTasksStore } from '@/app/components/plugins/plugin-page/store' import checkTaskStatus from '../../base/check-task-status' import { parseGitHubUrl } from '../../utils' type LoadedProps = { updatePayload: UpdateFromGitHubPayload uniqueIdentifier: string payload: PluginDeclaration repoUrl: string selectedVersion: string selectedPackage: string onBack: () => void onInstalled: () => void onFailed: (message?: string) => void } const i18nPrefix = 'plugin.installModal' const Loaded: React.FC = ({ updatePayload, uniqueIdentifier, payload, repoUrl, selectedVersion, selectedPackage, onBack, onInstalled, onFailed, }) => { const { t } = useTranslation() const [isInstalling, setIsInstalling] = React.useState(false) const setPluginTasksWithPolling = usePluginTasksStore(s => s.setPluginTasksWithPolling) const { check } = checkTaskStatus() const handleInstall = async () => { if (isInstalling) return setIsInstalling(true) try { const { owner, repo } = parseGitHubUrl(repoUrl) const { all_installed: isInstalled, task_id: taskId } = await installPackageFromGitHub( `${owner}/${repo}`, selectedVersion, selectedPackage, uniqueIdentifier, ) if (updatePayload && isInstalled) await uninstallPlugin(updatePayload.originalPackageInfo.id) if (isInstalled) { onInstalled() return } setPluginTasksWithPolling() await check({ taskId, pluginUniqueIdentifier: uniqueIdentifier, }) onInstalled() } catch (e) { if (typeof e === 'string') { onFailed(e) return } onFailed() } finally { setIsInstalling(false) } } return ( <>

{t(`${i18nPrefix}.readyToInstall`)}

{payload.version}} />
{!isInstalling && ( )}
) } export default Loaded