Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.3 KB
Raw Blame
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