import { useEffect, useMemo, useRef, useState } from "react"; import { Step } from "@/hooks/palmistry/use-steps"; import useSteps from "@/hooks/palmistry/use-steps"; import ScannedPhoto from "@/components/palmistry/scanned-photo/scanned-photo"; import { useSelector } from "react-redux"; import { selectors } from "@/store"; import { useNavigate } from "react-router-dom"; import routes from "@/routes"; import { IPalmistryLine } from "@/api/resources/Palmistry"; import { IPalmistryFingerLocal } from "@/store/palmistry"; const drawElementChangeDelay = 1500; const startDelay = 500; // const goNextDelay = 12000; export default function StepScanPhoto() { const steps = useSteps(); const navigate = useNavigate(); const storedPhoto = steps.getStoredValue(Step.Upload); const lines = useSelector(selectors.selectPalmistryLines); const fingers = useSelector(selectors.selectPalmistryFingers); const drawElements = useMemo(() => [...fingers, ...lines], [fingers, lines]); const [currentElementIndex, setCurrentElementIndex] = useState(0); const [smallPhotoState, setSmallPhotoState] = useState(false); const [title, setTitle] = useState(""); const [shouldDisplayPalmLines, setShouldDisplayPalmLines] = useState(false); const changeTitleTimeOut = useRef(); const prevElementIndex = useRef(null); const goNextElement = (delay: number) => { changeTitleTimeOut.current = setTimeout(() => { const title = (drawElements[currentElementIndex] as IPalmistryFingerLocal) .fingerName || drawElements[currentElementIndex].name; setTitle(title); setCurrentElementIndex((prevState) => prevState + 1); }, delay); }; useEffect(() => { if (!drawElements.length) { return navigate(routes.client.palmistryUpload()); } }, [drawElements, navigate]); useEffect(() => { // if (currentElementIndex === 0) { // new Promise((resolve) => setTimeout(resolve, startDelay)); // } if ( currentElementIndex < drawElements?.length && currentElementIndex !== prevElementIndex.current ) { prevElementIndex.current = currentElementIndex; goNextElement(drawElementChangeDelay); setShouldDisplayPalmLines( lines?.includes(drawElements[currentElementIndex] as IPalmistryLine) ); } if (currentElementIndex >= drawElements?.length) { const toSmallTimeOut = setTimeout(() => { setSmallPhotoState(true); }, drawElementChangeDelay); const goNextTimeOut = setTimeout( steps.goNext, drawElementChangeDelay * drawElements.length + 8000 ); return () => { clearTimeout(toSmallTimeOut); clearTimeout(goNextTimeOut); }; } return () => { if (changeTitleTimeOut.current) clearTimeout(changeTitleTimeOut.current); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [currentElementIndex]); // if (!storedPhoto) { // return Upload your photo; // } // console.log(shouldDisplayPalmLines); // return Upload your photo; return ( <>

{title}

We are putting together a comprehensive Palmistry Reading just for you!

Wow, looks like there is a lot we can tell about your ambitious and strong self-confident future.

); }