演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
import createFoldAnimInto from './create-fold-anim-into'
|
|
|
|
const useHideLogic = (onClose: () => void) => {
|
|
const onCloseRef = useRef(onClose)
|
|
useEffect(() => {
|
|
onCloseRef.current = onClose
|
|
}, [onClose])
|
|
|
|
const [controller] = useState(() => createFoldAnimInto(() => onCloseRef.current()))
|
|
const {
|
|
modalClassName,
|
|
foldIntoAnim: doFoldAnimInto,
|
|
clearCountDown,
|
|
countDownFoldIntoAnim,
|
|
} = controller
|
|
|
|
useEffect(() => clearCountDown, [clearCountDown])
|
|
|
|
const [isInstalling, doSetIsInstalling] = useState(false)
|
|
const setIsInstalling = useCallback(
|
|
(isInstalling: boolean) => {
|
|
if (!isInstalling) clearCountDown()
|
|
doSetIsInstalling(isInstalling)
|
|
},
|
|
[clearCountDown],
|
|
)
|
|
|
|
const foldAnimInto = useCallback(() => {
|
|
if (isInstalling) {
|
|
doFoldAnimInto()
|
|
return
|
|
}
|
|
onClose()
|
|
}, [doFoldAnimInto, isInstalling, onClose])
|
|
|
|
const handleStartToInstall = useCallback(() => {
|
|
setIsInstalling(true)
|
|
countDownFoldIntoAnim()
|
|
}, [countDownFoldIntoAnim, setIsInstalling])
|
|
|
|
return {
|
|
modalClassName,
|
|
foldAnimInto,
|
|
foldIntoTaskTrigger: doFoldAnimInto,
|
|
setIsInstalling,
|
|
handleStartToInstall,
|
|
}
|
|
}
|
|
|
|
export default useHideLogic
|