DiskManagementCoolDownSection.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { AnimatePresence, motion } from 'framer-motion'
  2. import { useEffect, useState } from 'react'
  3. import { DialogSection } from 'ui'
  4. import CountdownTimerRadial from '@/components/ui/CountdownTimer/CountdownTimerRadial'
  5. export const DiskMangementCoolDownSection = ({ visible }: { visible: boolean }) => {
  6. const [progress, setProgress] = useState(100)
  7. const [showCountdown, setShowCountdown] = useState(false)
  8. const [isJumping, setIsJumping] = useState(false)
  9. useEffect(() => {
  10. const startCountdown = () => {
  11. setShowCountdown(true)
  12. setProgress(100)
  13. const interval = setInterval(() => {
  14. setProgress((prevProgress) => {
  15. if (prevProgress <= 0) {
  16. clearInterval(interval)
  17. setIsJumping(true)
  18. setTimeout(() => {
  19. setIsJumping(false)
  20. setProgress(100)
  21. startCountdown() // Restart the countdown
  22. }, 300) // Duration of the jump animation
  23. return 0
  24. }
  25. return prevProgress - 1
  26. })
  27. }, 100)
  28. return () => clearInterval(interval)
  29. }
  30. const initialDelay = setTimeout(startCountdown, 1000)
  31. return () => clearTimeout(initialDelay)
  32. }, [])
  33. return (
  34. <AnimatePresence>
  35. {visible && (
  36. <motion.div
  37. initial={{ opacity: 1, height: 'auto' }}
  38. exit={{ opacity: 0, height: 0 }}
  39. transition={{ duration: 0.15 }}
  40. className="w-full"
  41. >
  42. <DialogSection className="bg-surface-100 text-sm text-foreground-light flex items-center gap-4 relative w-full border rounded-md">
  43. <div className="w-12 h-12">
  44. <AnimatePresence>
  45. {showCountdown && (
  46. <motion.div
  47. key="countdown-timer"
  48. initial={{ scale: 0.8, opacity: 0, y: -8 }}
  49. animate={{
  50. scale: isJumping ? 1.2 : 1,
  51. opacity: 1,
  52. y: isJumping ? -8 : 0,
  53. }}
  54. exit={{ scale: 0.8, opacity: 0, y: -8 }}
  55. transition={{
  56. duration: isJumping ? 0.3 : 0.8,
  57. type: 'spring',
  58. bounce: 0.6,
  59. }}
  60. >
  61. <CountdownTimerRadial progress={progress} />
  62. </motion.div>
  63. )}
  64. </AnimatePresence>
  65. </div>
  66. <div className="flex flex-col gap-0 grow">
  67. <p className="text-sm text-foreground">
  68. For 4 hours you will not be able to change any disk attributes.
  69. </p>
  70. <p className="text-sm text-foreground-light">
  71. There is a cooldown period enforced for any disk attribute modifications
  72. </p>
  73. </div>
  74. </DialogSection>
  75. </motion.div>
  76. )}
  77. </AnimatePresence>
  78. )
  79. }