import { IPalmistryPoint } from "@/api/resources/Palmistry"; import Title from "../Title"; import styles from "./styles.module.scss"; import { DisplayHand } from "@/hooks/handsGeneration/useHandsGeneration"; import { useRef } from "react"; interface IUsersHandsProps { title?: string; hands: DisplayHand[]; } function UsersHands({ title, hands }: IUsersHandsProps) { const linesRef = useRef([]); const getCoordinatesString = (points: IPalmistryPoint[]) => { const coordinatesString = `M ${points[0]?.x * 56} ${points[0]?.y * 75 }`; return points.reduce( (acc, point) => `${acc} L ${point?.x * 56} ${point?.y * 75}`, coordinatesString ); } const getLineLength = (line: SVGPathElement) => { return line?.getTotalLength(); }; return (
{!!title?.length && {title} }
{hands.map(({ image, lines, willBeRemoved }, index) => (
{`hand-${index}`} {/* {!!fingers.length && fingers?.map((finger, index) => { return ( ); })} */} {lines.map((line, index) => ( (linesRef.current[index] = el as SVGPathElement) } style={{ strokeDasharray: getLineLength(linesRef.current[index]) || 500, strokeDashoffset: getLineLength(linesRef.current[index]) || 500, }} /> ))}
))}
) } export default UsersHands