'use client'; import { useEffect, useRef, useState, type ReactNode, type RefObject } from 'react'; import { CLIPS, SHOTS } from './media'; import { IPhoneFrame } from './Devices'; import type { PhonePose, PhoneSceneHandle, PhoneScreen } from './phone-scene'; type Step = { label: string; title: string; body: string; screen: PhoneScreen; caption: string; pose: PhonePose; icon: ReactNode; }; const iconProps = { width: 18, height: 18, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.8, 'aria-hidden': true } as const; const STEPS: Step[] = [ { label: 'Step 01', title: 'Just start talking', body: 'Jotley transcribes as you speak. The Mac app transcribes system audio, browser, Zoom, Teams, podcasts and your mic at once. On iPhone, it is one tap from the Home Screen or Lock Screen, and it keeps transcribing when your phone is locked.', screen: { image: SHOTS.iphoneLive, video: CLIPS.iphoneLive }, caption: 'Live transcription on iPhone', pose: { rotateX: 0.04, rotateY: -0.38 }, icon: , }, { label: 'Step 02', title: 'AI does the work', body: 'Edit your transcript to fix names or clean up wording. Apple Intelligence can turn it into summaries, key points, action items and decisions right on your device.', screen: { image: SHOTS.iphoneSummary }, caption: 'A generated summary on iPhone', pose: { rotateX: -0.03, rotateY: 0.32 }, icon: , }, { label: 'Step 03', title: 'Sync & search', body: 'Search your notes and ask Apple Intelligence questions about them, right on your device. Optionally sync through iCloud or export as Markdown.', screen: { image: SHOTS.iphoneSearch }, caption: 'Finding notes with iPhone search', pose: { rotateX: 0.02, rotateY: -0.16 }, icon: , }, ]; /** 0 while the section is below the fold, 1 once its top has scrolled near the top of the viewport. */ function entryProgress(section: HTMLElement | null): number { if (!section) return 1; const viewport = window.innerHeight; const top = section.getBoundingClientRect().top; return Math.min(1, Math.max(0, (viewport - top) / (viewport * 0.95))); } function PhoneStage({ active, sectionRef }: { active: number; sectionRef: RefObject }) { const containerRef = useRef(null); const handleRef = useRef(null); const activeRef = useRef(active); const [fallback, setFallback] = useState(false); const [ready, setReady] = useState(false); activeRef.current = active; useEffect(() => { handleRef.current?.show(active); }, [active]); useEffect(() => { const container = containerRef.current; if (!container) return; let cancelled = false; let handle: PhoneSceneHandle | null = null; let visibility: IntersectionObserver | null = null; // Only pull in three.js once the section is getting close. const loader = new IntersectionObserver( async ([entry]) => { if (!entry.isIntersecting) return; loader.disconnect(); try { const { createPhoneScene } = await import('./phone-scene'); if (cancelled) return; handle = await createPhoneScene(container, { screens: STEPS.map((step) => step.screen), poses: STEPS.map((step) => step.pose), reducedMotion: window.matchMedia('(prefers-reduced-motion: reduce)').matches, getEntryProgress: () => entryProgress(sectionRef.current), }); if (cancelled) { handle.dispose(); return; } handleRef.current = handle; handle.show(activeRef.current); setReady(true); visibility = new IntersectionObserver(([v]) => handle?.setActive(v.intersectionRatio >= 0.3), { threshold: 0.3 }); visibility.observe(container); } catch { setFallback(true); } }, { rootMargin: '100% 0px' } ); loader.observe(container); return () => { cancelled = true; loader.disconnect(); visibility?.disconnect(); handle?.dispose(); handleRef.current = null; }; }, [sectionRef]); return (
{fallback && ( )}
); } export default function HowItWorks() { const [active, setActive] = useState(0); const [narrow, setNarrow] = useState(false); const sectionRef = useRef(null); const stepsRef = useRef(null); const stepRefs = useRef<(HTMLLIElement | null)[]>([]); useEffect(() => { const query = window.matchMedia('(max-width: 900px)'); const sync = () => setNarrow(query.matches); sync(); query.addEventListener('change', sync); return () => query.removeEventListener('change', sync); }, []); useEffect(() => { // Wide screens: a step becomes active as it scrolls across the middle of the // viewport. Narrow screens: the steps are a swipeable carousel under the phone, // and the card that's mostly in view is the active one. const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (entry.isIntersecting) setActive(Number((entry.target as HTMLElement).dataset.index)); }); }, narrow ? { root: stepsRef.current, threshold: 0.6 } : { rootMargin: '-50% 0px -50% 0px' } ); stepRefs.current.forEach((step) => step && observer.observe(step)); return () => observer.disconnect(); }, [narrow]); const showStep = (index: number) => { const list = stepsRef.current; const step = stepRefs.current[index]; if (!list || !step) return; list.scrollTo({ left: step.offsetLeft - (list.clientWidth - step.clientWidth) / 2, behavior: 'smooth' }); }; return (
); }