diff --git a/src/components/toolbox/countdown-timer/timers/timer/timer.tsx b/src/components/toolbox/countdown-timer/timers/timer/timer.tsx index f81fe22..eb49645 100644 --- a/src/components/toolbox/countdown-timer/timers/timer/timer.tsx +++ b/src/components/toolbox/countdown-timer/timers/timer/timer.tsx @@ -5,6 +5,7 @@ import { IoRefresh, IoTrashOutline, } from 'react-icons/io5/index'; +import { motion } from 'framer-motion'; import { ReverseTimer } from './reverse-timer'; @@ -29,13 +30,20 @@ export function Timer({ id }: TimerProps) { const { name, spent, total } = useCountdownTimers(state => state.getTimer(id), - ); + ) || { name: '', spent: 0, total: 0 }; + + const [isDeleting, setIsDeleting] = useState(false); + const [snapshot, setSnapshot] = useState({ spent: 0, total: 0 }); + const tick = useCountdownTimers(state => state.tick); const rename = useCountdownTimers(state => state.rename); const reset = useCountdownTimers(state => state.reset); const deleteTimer = useCountdownTimers(state => state.delete); - const left = useMemo(() => total - spent, [total, spent]); + const left = useMemo( + () => (isDeleting ? snapshot.total - snapshot.spent : total - spent), + [total, spent, isDeleting, snapshot], + ); const hours = useMemo(() => Math.floor(left / 3600), [left]); const minutes = useMemo(() => Math.floor((left % 3600) / 60), [left]); @@ -68,6 +76,9 @@ export function Timer({ id }: TimerProps) { const handleDelete = () => { if (isRunning) return showSnackbar('Please first stop the timer.'); + setIsDeleting(true); + setSnapshot({ spent, total }); + deleteTimer(id); }; @@ -128,8 +139,20 @@ export function Timer({ id }: TimerProps) { }; }, [isRunning, tick, id, spent, total, left]); + const variants = { + enter: { opacity: 1 }, + exit: { opacity: 0 }, + initial: { opacity: 0 }, + }; + return ( -
+
-
+ ); } diff --git a/src/components/toolbox/countdown-timer/timers/timers.tsx b/src/components/toolbox/countdown-timer/timers/timers.tsx index daa35b7..2e6b8fb 100644 --- a/src/components/toolbox/countdown-timer/timers/timers.tsx +++ b/src/components/toolbox/countdown-timer/timers/timers.tsx @@ -1,4 +1,5 @@ import { useMemo } from 'react'; +import { AnimatePresence } from 'framer-motion'; import { Timer } from './timer'; import { Notice } from './notice'; @@ -30,9 +31,11 @@ export function Timers() { )}
- {timers.map(timer => ( - - ))} + + {timers.map(timer => ( + + ))} +