feat: can upload and parse bundle
parent
972eaa5948
commit
c5c06c18f1
@ -0,0 +1,48 @@
|
|||||||
|
'use client'
|
||||||
|
import type { FC } from 'react'
|
||||||
|
import React, { useCallback, useState } from 'react'
|
||||||
|
import { InstallStep } from '../../types'
|
||||||
|
import Install from './steps/install'
|
||||||
|
import Installed from './steps/installed'
|
||||||
|
import type { Dependency, InstallStatusResponse, Plugin } from '../../types'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
step: InstallStep
|
||||||
|
onStepChange: (step: InstallStep) => void,
|
||||||
|
dependencies: Dependency[]
|
||||||
|
onClose: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const ReadyToInstall: FC<Props> = ({
|
||||||
|
step,
|
||||||
|
onStepChange,
|
||||||
|
dependencies,
|
||||||
|
onClose,
|
||||||
|
}) => {
|
||||||
|
const [installedPlugins, setInstalledPlugins] = useState<Plugin[]>([])
|
||||||
|
const [installStatus, setInstallStatus] = useState<InstallStatusResponse[]>([])
|
||||||
|
const handleInstalled = useCallback((plugins: Plugin[], installStatus: InstallStatusResponse[]) => {
|
||||||
|
setInstallStatus(installStatus)
|
||||||
|
setInstalledPlugins(plugins)
|
||||||
|
onStepChange(InstallStep.installed)
|
||||||
|
}, [onStepChange])
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{step === InstallStep.readyToInstall && (
|
||||||
|
<Install
|
||||||
|
fromDSLPayload={dependencies}
|
||||||
|
onCancel={onClose}
|
||||||
|
onInstalled={handleInstalled}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{step === InstallStep.installed && (
|
||||||
|
<Installed
|
||||||
|
list={installedPlugins}
|
||||||
|
installStatus={installStatus}
|
||||||
|
onCancel={onClose}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
export default React.memo(ReadyToInstall)
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
'use client'
|
||||||
|
import type { FC } from 'react'
|
||||||
|
import React, { useCallback } from 'react'
|
||||||
|
import type { PluginDeclaration } from '../../types'
|
||||||
|
import { InstallStep } from '../../types'
|
||||||
|
import Install from './steps/install'
|
||||||
|
import Installed from '../base/installed'
|
||||||
|
import { useInvalidateInstalledPluginList } from '@/service/use-plugins'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
step: InstallStep
|
||||||
|
onStepChange: (step: InstallStep) => void,
|
||||||
|
onClose: () => void
|
||||||
|
uniqueIdentifier: string | null,
|
||||||
|
manifest: PluginDeclaration | null,
|
||||||
|
errorMsg: string | null,
|
||||||
|
onError: (errorMsg: string) => void,
|
||||||
|
}
|
||||||
|
|
||||||
|
const ReadyToInstall: FC<Props> = ({
|
||||||
|
step,
|
||||||
|
onStepChange,
|
||||||
|
onClose,
|
||||||
|
uniqueIdentifier,
|
||||||
|
manifest,
|
||||||
|
errorMsg,
|
||||||
|
onError,
|
||||||
|
}) => {
|
||||||
|
const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
|
||||||
|
|
||||||
|
const handleInstalled = useCallback(() => {
|
||||||
|
invalidateInstalledPluginList()
|
||||||
|
onStepChange(InstallStep.installed)
|
||||||
|
}, [invalidateInstalledPluginList, onStepChange])
|
||||||
|
|
||||||
|
const handleFailed = useCallback((errorMsg?: string) => {
|
||||||
|
onStepChange(InstallStep.installFailed)
|
||||||
|
if (errorMsg)
|
||||||
|
onError(errorMsg)
|
||||||
|
}, [onError, onStepChange])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{
|
||||||
|
step === InstallStep.readyToInstall && (
|
||||||
|
<Install
|
||||||
|
uniqueIdentifier={uniqueIdentifier!}
|
||||||
|
payload={manifest!}
|
||||||
|
onCancel={onClose}
|
||||||
|
onInstalled={handleInstalled}
|
||||||
|
onFailed={handleFailed}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
([InstallStep.uploadFailed, InstallStep.installed, InstallStep.installFailed].includes(step)) && (
|
||||||
|
<Installed
|
||||||
|
payload={manifest}
|
||||||
|
isFailed={[InstallStep.uploadFailed, InstallStep.installFailed].includes(step)}
|
||||||
|
errMsg={errorMsg}
|
||||||
|
onCancel={onClose}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
export default React.memo(ReadyToInstall)
|
||||||
Loading…
Reference in New Issue