"use client"; import { LazyMotion, domAnimation, m } from "framer-motion"; import { useContext, useEffect, useLayoutEffect, useRef, useState } from "react"; import { useStore } from "zustand"; import { DAY_CELL_WIDTH } from "../constants"; import { TBContext } from "../store"; export function CellHighlightContainer({ children }: { children: React.ReactNode }) { const store = useContext(TBContext); if (!store) throw new Error("Missing TBContext.Provider in the tree"); const [isAnimating, setIsAnimating] = useState(false); const componentContainerRef = useRef(null); const { x, y, height, isHover, updateDimensions, setContainerRef } = useStore(store, (state) => state); useEffect(() => { let timeout: NodeJS.Timeout | null = null; if (isHover) { setIsAnimating(true); } else { timeout = setTimeout(() => setIsAnimating(false), 1000); } return () => { timeout && clearTimeout(timeout); }; }, [isHover]); useLayoutEffect(() => { const handleUpdate = () => { updateDimensions(); }; const resizeObserver = new ResizeObserver(() => handleUpdate()); const currentContainerRef = componentContainerRef.current; setContainerRef(componentContainerRef); if (currentContainerRef) { resizeObserver.observe(currentContainerRef); } return () => { if (currentContainerRef) { resizeObserver.unobserve(currentContainerRef); } }; }, [componentContainerRef, setContainerRef, updateDimensions]); return (
{children}
); }