feat: local and bundle support hide anim

This commit is contained in:
Joel 2025-01-09 11:16:33 +08:00
parent 9822445c1e
commit 192af8df9f
6 changed files with 49 additions and 7 deletions

View File

@ -6,6 +6,8 @@ import { InstallStep } from '../../types'
import type { Dependency } from '../../types' import type { Dependency } from '../../types'
import ReadyToInstall from './ready-to-install' import ReadyToInstall from './ready-to-install'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import useHideLogic from '../hooks/use-hide-logic'
import cn from '@/utils/classnames'
const i18nPrefix = 'plugin.installModal' const i18nPrefix = 'plugin.installModal'
@ -30,6 +32,13 @@ const InstallBundle: FC<Props> = ({
const { t } = useTranslation() const { t } = useTranslation()
const [step, setStep] = useState<InstallStep>(installType === InstallType.fromMarketplace ? InstallStep.readyToInstall : InstallStep.uploading) const [step, setStep] = useState<InstallStep>(installType === InstallType.fromMarketplace ? InstallStep.readyToInstall : InstallStep.uploading)
const {
modalClassName,
foldAnimInto,
setIsInstalling,
handleStartToInstall,
} = useHideLogic(onClose)
const getTitle = useCallback(() => { const getTitle = useCallback(() => {
if (step === InstallStep.uploadFailed) if (step === InstallStep.uploadFailed)
return t(`${i18nPrefix}.uploadFailed`) return t(`${i18nPrefix}.uploadFailed`)
@ -42,8 +51,8 @@ const InstallBundle: FC<Props> = ({
return ( return (
<Modal <Modal
isShow={true} isShow={true}
onClose={onClose} onClose={foldAnimInto}
className='flex min-w-[560px] p-0 flex-col items-start rounded-2xl border-[0.5px] border-components-panel-border bg-components-panel-bg shadows-shadow-xl' className={cn(modalClassName, 'flex min-w-[560px] p-0 flex-col items-start rounded-2xl border-[0.5px] border-components-panel-border bg-components-panel-bg shadows-shadow-xl')}
closable closable
> >
<div className='flex pt-6 pl-6 pb-3 pr-14 items-start gap-2 self-stretch'> <div className='flex pt-6 pl-6 pb-3 pr-14 items-start gap-2 self-stretch'>
@ -54,6 +63,8 @@ const InstallBundle: FC<Props> = ({
<ReadyToInstall <ReadyToInstall
step={step} step={step}
onStepChange={setStep} onStepChange={setStep}
onStartToInstall={handleStartToInstall}
setIsInstalling={setIsInstalling}
allPlugins={fromDSLPayload} allPlugins={fromDSLPayload}
onClose={onClose} onClose={onClose}
/> />

View File

@ -9,6 +9,8 @@ import type { Dependency, InstallStatusResponse, Plugin } from '../../types'
type Props = { type Props = {
step: InstallStep step: InstallStep
onStepChange: (step: InstallStep) => void, onStepChange: (step: InstallStep) => void,
onStartToInstall: () => void
setIsInstalling: (isInstalling: boolean) => void
allPlugins: Dependency[] allPlugins: Dependency[]
onClose: () => void onClose: () => void
isFromMarketPlace?: boolean isFromMarketPlace?: boolean
@ -17,6 +19,8 @@ type Props = {
const ReadyToInstall: FC<Props> = ({ const ReadyToInstall: FC<Props> = ({
step, step,
onStepChange, onStepChange,
onStartToInstall,
setIsInstalling,
allPlugins, allPlugins,
onClose, onClose,
isFromMarketPlace, isFromMarketPlace,
@ -27,13 +31,15 @@ const ReadyToInstall: FC<Props> = ({
setInstallStatus(installStatus) setInstallStatus(installStatus)
setInstalledPlugins(plugins) setInstalledPlugins(plugins)
onStepChange(InstallStep.installed) onStepChange(InstallStep.installed)
}, [onStepChange]) setIsInstalling(false)
}, [onStepChange, setIsInstalling])
return ( return (
<> <>
{step === InstallStep.readyToInstall && ( {step === InstallStep.readyToInstall && (
<Install <Install
allPlugins={allPlugins} allPlugins={allPlugins}
onCancel={onClose} onCancel={onClose}
onStartToInstall={onStartToInstall}
onInstalled={handleInstalled} onInstalled={handleInstalled}
isFromMarketPlace={isFromMarketPlace} isFromMarketPlace={isFromMarketPlace}
/> />

View File

@ -12,6 +12,7 @@ const i18nPrefix = 'plugin.installModal'
type Props = { type Props = {
allPlugins: Dependency[] allPlugins: Dependency[]
onStartToInstall?: () => void
onInstalled: (plugins: Plugin[], installStatus: InstallStatusResponse[]) => void onInstalled: (plugins: Plugin[], installStatus: InstallStatusResponse[]) => void
onCancel: () => void onCancel: () => void
isFromMarketPlace?: boolean isFromMarketPlace?: boolean
@ -20,6 +21,7 @@ type Props = {
const Install: FC<Props> = ({ const Install: FC<Props> = ({
allPlugins, allPlugins,
onStartToInstall,
onInstalled, onInstalled,
onCancel, onCancel,
isFromMarketPlace, isFromMarketPlace,
@ -65,6 +67,7 @@ const Install: FC<Props> = ({
}, },
}) })
const handleInstall = () => { const handleInstall = () => {
onStartToInstall?.()
installOrUpdate({ installOrUpdate({
payload: allPlugins.filter((_d, index) => selectedIndexes.includes(index)), payload: allPlugins.filter((_d, index) => selectedIndexes.includes(index)),
plugin: selectedPlugins, plugin: selectedPlugins,

View File

@ -9,6 +9,8 @@ import { useTranslation } from 'react-i18next'
import useGetIcon from '@/app/components/plugins/install-plugin/base/use-get-icon' import useGetIcon from '@/app/components/plugins/install-plugin/base/use-get-icon'
import ReadyToInstallPackage from './ready-to-install' import ReadyToInstallPackage from './ready-to-install'
import ReadyToInstallBundle from '../install-bundle/ready-to-install' import ReadyToInstallBundle from '../install-bundle/ready-to-install'
import useHideLogic from '../hooks/use-hide-logic'
import cn from '@/utils/classnames'
const i18nPrefix = 'plugin.installModal' const i18nPrefix = 'plugin.installModal'
@ -31,6 +33,13 @@ const InstallFromLocalPackage: React.FC<InstallFromLocalPackageProps> = ({
const isBundle = file.name.endsWith('.difybndl') const isBundle = file.name.endsWith('.difybndl')
const [dependencies, setDependencies] = useState<Dependency[]>([]) const [dependencies, setDependencies] = useState<Dependency[]>([])
const {
modalClassName,
foldAnimInto,
setIsInstalling,
handleStartToInstall,
} = useHideLogic(onClose)
const getTitle = useCallback(() => { const getTitle = useCallback(() => {
if (step === InstallStep.uploadFailed) if (step === InstallStep.uploadFailed)
return t(`${i18nPrefix}.uploadFailed`) return t(`${i18nPrefix}.uploadFailed`)
@ -76,8 +85,8 @@ const InstallFromLocalPackage: React.FC<InstallFromLocalPackageProps> = ({
return ( return (
<Modal <Modal
isShow={true} isShow={true}
onClose={onClose} onClose={foldAnimInto}
className='flex min-w-[560px] p-0 flex-col items-start rounded-2xl border-[0.5px] border-components-panel-border bg-components-panel-bg shadows-shadow-xl' className={cn(modalClassName, 'flex min-w-[560px] p-0 flex-col items-start rounded-2xl border-[0.5px] border-components-panel-border bg-components-panel-bg shadows-shadow-xl')}
closable closable
> >
<div className='flex pt-6 pl-6 pb-3 pr-14 items-start gap-2 self-stretch'> <div className='flex pt-6 pl-6 pb-3 pr-14 items-start gap-2 self-stretch'>
@ -99,6 +108,8 @@ const InstallFromLocalPackage: React.FC<InstallFromLocalPackageProps> = ({
<ReadyToInstallBundle <ReadyToInstallBundle
step={step} step={step}
onStepChange={setStep} onStepChange={setStep}
onStartToInstall={handleStartToInstall}
setIsInstalling={setIsInstalling}
onClose={onClose} onClose={onClose}
allPlugins={dependencies} allPlugins={dependencies}
/> />
@ -106,6 +117,8 @@ const InstallFromLocalPackage: React.FC<InstallFromLocalPackageProps> = ({
<ReadyToInstallPackage <ReadyToInstallPackage
step={step} step={step}
onStepChange={setStep} onStepChange={setStep}
onStartToInstall={handleStartToInstall}
setIsInstalling={setIsInstalling}
onClose={onClose} onClose={onClose}
uniqueIdentifier={uniqueIdentifier} uniqueIdentifier={uniqueIdentifier}
manifest={manifest} manifest={manifest}

View File

@ -10,6 +10,8 @@ import useRefreshPluginList from '../hooks/use-refresh-plugin-list'
type Props = { type Props = {
step: InstallStep step: InstallStep
onStepChange: (step: InstallStep) => void, onStepChange: (step: InstallStep) => void,
onStartToInstall: () => void
setIsInstalling: (isInstalling: boolean) => void
onClose: () => void onClose: () => void
uniqueIdentifier: string | null, uniqueIdentifier: string | null,
manifest: PluginDeclaration | null, manifest: PluginDeclaration | null,
@ -20,6 +22,8 @@ type Props = {
const ReadyToInstall: FC<Props> = ({ const ReadyToInstall: FC<Props> = ({
step, step,
onStepChange, onStepChange,
onStartToInstall,
setIsInstalling,
onClose, onClose,
uniqueIdentifier, uniqueIdentifier,
manifest, manifest,
@ -31,13 +35,15 @@ const ReadyToInstall: FC<Props> = ({
const handleInstalled = useCallback(() => { const handleInstalled = useCallback(() => {
onStepChange(InstallStep.installed) onStepChange(InstallStep.installed)
refreshPluginList(manifest) refreshPluginList(manifest)
}, [manifest, onStepChange, refreshPluginList]) setIsInstalling(false)
}, [manifest, onStepChange, refreshPluginList, setIsInstalling])
const handleFailed = useCallback((errorMsg?: string) => { const handleFailed = useCallback((errorMsg?: string) => {
onStepChange(InstallStep.installFailed) onStepChange(InstallStep.installFailed)
setIsInstalling(false)
if (errorMsg) if (errorMsg)
onError(errorMsg) onError(errorMsg)
}, [onError, onStepChange]) }, [onError, onStepChange, setIsInstalling])
return ( return (
<> <>
@ -49,6 +55,7 @@ const ReadyToInstall: FC<Props> = ({
onCancel={onClose} onCancel={onClose}
onInstalled={handleInstalled} onInstalled={handleInstalled}
onFailed={handleFailed} onFailed={handleFailed}
onStartToInstall={onStartToInstall}
/> />
) )
} }

View File

@ -85,6 +85,8 @@ const InstallFromMarketplace: React.FC<InstallFromMarketplaceProps> = ({
<ReadyToInstallBundle <ReadyToInstallBundle
step={step} step={step}
onStepChange={setStep} onStepChange={setStep}
onStartToInstall={handleStartToInstall}
setIsInstalling={setIsInstalling}
onClose={onClose} onClose={onClose}
allPlugins={dependencies!} allPlugins={dependencies!}
isFromMarketPlace isFromMarketPlace