import React, { useEffect, useState } from "react"; import _ from "lodash"; import timerIcon from "../../../assets/icons/timer.svg"; import QuestionBox from "./Question"; import scroll from "../../../utils/scroll"; export default function Test({ title, duration, questions }) { const [translateY, setTranslateY] = useState(0); const [testPosition, setTestPosition] = useState(null); useEffect(() => { setTranslateY(() => scroll.linearFormula( window.scrollY > 5 * window.innerHeight ? 5 * window.innerHeight : window.scrollY, 0, -101, 4.5 * window.innerHeight, 5 * window.innerHeight ) ); window.addEventListener("scroll", () => { testTransformHandler(window.scrollY); if (window.scrollY > 1000) { localStorage.setItem( "testRect", JSON.stringify( document.getElementById("test").getBoundingClientRect() ) ); } }); }, []); const testTransformHandler = (scrollY) => { const height = window.innerHeight; if (scrollY <= 4.5 * height) { setTranslateY(() => 0); setTestPosition(() => null); } else if (scrollY > 4.5 * height && scrollY < 5 * height) { setTranslateY(() => scroll.linearFormula(scrollY, 0, -101, 4.5 * height, 5 * height) ); setTestPosition(() => null); } }; return (