({ isActive, onDismiss })
| 57 | ]; |
| 58 | |
| 59 | const LocalOnboardingTutorial: React.FC<LocalOnboardingTutorialProps> = ({ isActive, onDismiss }) => { |
| 60 | const [step, setStep] = useState(0); |
| 61 | const [rect, setRect] = useState<DOMRect | null>(null); |
| 62 | const [dismissedSteps, setDismissedSteps] = useState<Set<string>>(new Set()); |
| 63 | |
| 64 | const current = STEPS[step] ?? null; |
| 65 | const isCurrentDismissed = current ? dismissedSteps.has(current.id) : false; |
| 66 | |
| 67 | useEffect(() => { |
| 68 | if (!isActive) { setStep(0); setDismissedSteps(new Set()); return; } |
| 69 | }, [isActive]); |
| 70 | |
| 71 | useEffect(() => { |
| 72 | if (!current?.targetSelector) { setRect(null); return; } |
| 73 | let rafId: number; |
| 74 | const loop = () => { |
| 75 | const el = firstVisible(current.targetSelector); |
| 76 | if (el) setRect(el.getBoundingClientRect()); |
| 77 | rafId = requestAnimationFrame(loop); |
| 78 | }; |
| 79 | rafId = requestAnimationFrame(loop); |
| 80 | return () => cancelAnimationFrame(rafId); |
| 81 | }, [current?.targetSelector]); |
| 82 | |
| 83 | useEffect(() => { |
| 84 | if (!isActive || current?.action !== 'click' || !current.targetSelector) return; |
| 85 | |
| 86 | const handleClick = (e: Event) => { |
| 87 | const target = e.target as HTMLElement; |
| 88 | const highlighted = firstVisible(current.targetSelector); |
| 89 | if (highlighted && (highlighted === target || highlighted.contains(target))) { |
| 90 | if (step < STEPS.length - 1) { |
| 91 | setStep(s => s + 1); |
| 92 | } else { |
| 93 | onDismiss(); |
| 94 | } |
| 95 | } |
| 96 | }; |
| 97 | |
| 98 | document.addEventListener('click', handleClick, true); |
| 99 | return () => document.removeEventListener('click', handleClick, true); |
| 100 | }, [isActive, step, current]); |
| 101 | |
| 102 | useEffect(() => { |
| 103 | if (!isActive || current?.action !== 'event' || !current.waitForEvent) return; |
| 104 | |
| 105 | const advance = () => { |
| 106 | if (step < STEPS.length - 1) { |
| 107 | setStep(s => s + 1); |
| 108 | } else { |
| 109 | onDismiss(); |
| 110 | } |
| 111 | }; |
| 112 | |
| 113 | window.addEventListener(current.waitForEvent, advance); |
| 114 | return () => window.removeEventListener(current.waitForEvent!, advance); |
| 115 | }, [isActive, step, current]); |
| 116 |
nothing calls this directly
no test coverage detected