feat: install countdown

pull/12560/head
Joel 1 year ago
parent 61237e8037
commit 6483d20f56

@ -1,7 +1,8 @@
import { sleep } from '@/utils' import { sleep } from '@/utils'
// modalElem fold into plugin install task btn
const animTime = 2000 const animTime = 2000
const modalClassName = 'install-modal'
const COUNT_DOWN_TIME = 15000 // 15s
function getElemCenter(elem: HTMLElement) { function getElemCenter(elem: HTMLElement) {
const rect = elem.getBoundingClientRect() const rect = elem.getBoundingClientRect()
@ -12,7 +13,13 @@ function getElemCenter(elem: HTMLElement) {
} }
const useFoldAnimInto = (onClose: () => void) => { const useFoldAnimInto = (onClose: () => void) => {
return async function foldIntoAnim(modalClassName: string) { let countDownRunId: number
const clearCountDown = () => {
clearTimeout(countDownRunId)
}
// modalElem fold into plugin install task btn
const foldIntoAnim = async () => {
clearCountDown()
const modalElem = document.querySelector(`.${modalClassName}`) as HTMLElement const modalElem = document.querySelector(`.${modalClassName}`) as HTMLElement
const pluginTaskTriggerElem = document.getElementById('plugin-task-trigger') const pluginTaskTriggerElem = document.getElementById('plugin-task-trigger')
@ -32,6 +39,19 @@ const useFoldAnimInto = (onClose: () => void) => {
await sleep(animTime) await sleep(animTime)
onClose() onClose()
} }
const countDownFoldIntoAnim = async () => {
countDownRunId = window.setTimeout(() => {
foldIntoAnim()
}, COUNT_DOWN_TIME)
}
return {
modalClassName,
foldIntoAnim,
clearCountDown,
countDownFoldIntoAnim,
}
} }
export default useFoldAnimInto export default useFoldAnimInto

@ -1,6 +1,6 @@
'use client' 'use client'
import React, { useCallback, useRef, useState } from 'react' import React, { useCallback, useState } from 'react'
import Modal from '@/app/components/base/modal' import Modal from '@/app/components/base/modal'
import type { Dependency, Plugin, PluginManifestInMarket } from '../../types' import type { Dependency, Plugin, PluginManifestInMarket } from '../../types'
import { InstallStep } from '../../types' import { InstallStep } from '../../types'
@ -37,8 +37,27 @@ const InstallFromMarketplace: React.FC<InstallFromMarketplaceProps> = ({
const [errorMsg, setErrorMsg] = useState<string | null>(null) const [errorMsg, setErrorMsg] = useState<string | null>(null)
const { refreshPluginList } = useRefreshPluginList() const { refreshPluginList } = useRefreshPluginList()
const modalRef = useRef<HTMLElement>(null) const {
const foldAnimInto = useFoldAnimInto(onClose) modalClassName,
foldIntoAnim: doFoldAnimInto,
clearCountDown,
countDownFoldIntoAnim,
} = useFoldAnimInto(onClose)
const [isInstalling, setIsInstalling] = useState(false)
const foldAnimInto = useCallback(() => {
if (isInstalling) {
doFoldAnimInto()
return
}
onClose()
}, [doFoldAnimInto, isInstalling, onClose])
const handleStartToInstall = useCallback(() => {
setIsInstalling(true)
countDownFoldIntoAnim()
}, [countDownFoldIntoAnim])
const getTitle = useCallback(() => { const getTitle = useCallback(() => {
if (isBundle && step === InstallStep.installed) if (isBundle && step === InstallStep.installed)
@ -61,12 +80,10 @@ const InstallFromMarketplace: React.FC<InstallFromMarketplaceProps> = ({
setErrorMsg(errorMsg) setErrorMsg(errorMsg)
}, []) }, [])
const modalClassName = 'install-modal'
return ( return (
<Modal <Modal
isShow={true} isShow={true}
onClose={() => step === InstallStep.readyToInstall ? foldAnimInto(modalClassName) : onClose()} onClose={foldAnimInto}
wrapperClassName='z-[9999]' wrapperClassName='z-[9999]'
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')} 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
@ -94,6 +111,8 @@ const InstallFromMarketplace: React.FC<InstallFromMarketplaceProps> = ({
onCancel={onClose} onCancel={onClose}
onInstalled={handleInstalled} onInstalled={handleInstalled}
onFailed={handleFailed} onFailed={handleFailed}
onStartToInstall={handleStartToInstall}
clearCountDown={clearCountDown}
/> />
)} )}
{ {

@ -22,6 +22,7 @@ type Props = {
onCancel: () => void onCancel: () => void
onStartToInstall?: () => void onStartToInstall?: () => void
onInstalled: () => void onInstalled: () => void
clearCountDown: () => void
onFailed: (message?: string) => void onFailed: (message?: string) => void
} }
@ -31,6 +32,7 @@ const Installed: FC<Props> = ({
onCancel, onCancel,
onStartToInstall, onStartToInstall,
onInstalled, onInstalled,
clearCountDown,
onFailed, onFailed,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
@ -56,6 +58,7 @@ const Installed: FC<Props> = ({
useEffect(() => { useEffect(() => {
if (hasInstalled && uniqueIdentifier === installedInfoPayload.uniqueIdentifier) if (hasInstalled && uniqueIdentifier === installedInfoPayload.uniqueIdentifier)
onInstalled() onInstalled()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasInstalled]) }, [hasInstalled])
const handleCancel = () => { const handleCancel = () => {
@ -67,7 +70,6 @@ const Installed: FC<Props> = ({
if (isInstalling) return if (isInstalling) return
onStartToInstall?.() onStartToInstall?.()
setIsInstalling(true) setIsInstalling(true)
try { try {
let taskId let taskId
let isInstalled let isInstalled
@ -91,6 +93,8 @@ const Installed: FC<Props> = ({
isInstalled = all_installed isInstalled = all_installed
} }
clearCountDown()
if (isInstalled) { if (isInstalled) {
onInstalled() onInstalled()
return return

Loading…
Cancel
Save