Branchwell

Jotley / website · jotley.ai / src / app / components / home / HowItWorks.tsx

Raw 8.3 KB on 9f5272c5f39b346af9e28d5fc68fe05aab70ce39
1'use client';
2
3import { useEffect, useRef, useState, type ReactNode, type RefObject } from 'react';
4import { CLIPS, SHOTS } from './media';
5import { IPhoneFrame } from './Devices';
6import type { PhonePose, PhoneSceneHandle, PhoneScreen } from './phone-scene';
7
8type Step = {
9 label: string;
10 title: string;
11 body: string;
12 screen: PhoneScreen;
13 caption: string;
14 pose: PhonePose;
15 icon: ReactNode;
16};
17
18const iconProps = { width: 18, height: 18, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.8, 'aria-hidden': true } as const;
19
20const STEPS: Step[] = [
21 {
22 label: 'Step 01',
23 title: 'Just start talking',
24 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.',
25 screen: { image: SHOTS.iphoneLive, video: CLIPS.iphoneLive },
26 caption: 'Live transcription on iPhone',
27 pose: { rotateX: 0.04, rotateY: -0.38 },
28 icon: <svg {...iconProps}><path d="M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4m-4-8a3 3 0 01-3-3V5a3 3 0 116 0v6a3 3 0 01-3 3z" strokeLinecap="round" strokeLinejoin="round" /></svg>,
29 },
30 {
31 label: 'Step 02',
32 title: 'AI does the work',
33 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.',
34 screen: { image: SHOTS.iphoneSummary },
35 caption: 'A generated summary on iPhone',
36 pose: { rotateX: -0.03, rotateY: 0.32 },
37 icon: <svg {...iconProps}><path d="M12 2l1.7 6.3L20 10l-6.3 1.7L12 18l-1.7-6.3L4 10l6.3-1.7z" strokeLinejoin="round" /></svg>,
38 },
39 {
40 label: 'Step 03',
41 title: 'Sync & search',
42 body: 'Search your notes and ask Apple Intelligence questions about them, right on your device. Optionally sync through iCloud or export as Markdown.',
43 screen: { image: SHOTS.iphoneSearch },
44 caption: 'Finding notes with iPhone search',
45 pose: { rotateX: 0.02, rotateY: -0.16 },
46 icon: <svg {...iconProps}><path d="M21 21l-5.2-5.2M10.5 18a7.5 7.5 0 100-15 7.5 7.5 0 000 15z" strokeLinecap="round" /></svg>,
47 },
48];
49
50/** 0 while the section is below the fold, 1 once its top has scrolled near the top of the viewport. */
51function entryProgress(section: HTMLElement | null): number {
52 if (!section) return 1;
53 const viewport = window.innerHeight;
54 const top = section.getBoundingClientRect().top;
55 return Math.min(1, Math.max(0, (viewport - top) / (viewport * 0.95)));
56}
57
58function PhoneStage({ active, sectionRef }: { active: number; sectionRef: RefObject<HTMLElement | null> }) {
59 const containerRef = useRef<HTMLDivElement>(null);
60 const handleRef = useRef<PhoneSceneHandle | null>(null);
61 const activeRef = useRef(active);
62 const [fallback, setFallback] = useState(false);
63 const [ready, setReady] = useState(false);
64
65 activeRef.current = active;
66
67 useEffect(() => {
68 handleRef.current?.show(active);
69 }, [active]);
70
71 useEffect(() => {
72 const container = containerRef.current;
73 if (!container) return;
74 let cancelled = false;
75 let handle: PhoneSceneHandle | null = null;
76 let visibility: IntersectionObserver | null = null;
77
78 // Only pull in three.js once the section is getting close.
79 const loader = new IntersectionObserver(
80 async ([entry]) => {
81 if (!entry.isIntersecting) return;
82 loader.disconnect();
83 try {
84 const { createPhoneScene } = await import('./phone-scene');
85 if (cancelled) return;
86 handle = await createPhoneScene(container, {
87 screens: STEPS.map((step) => step.screen),
88 poses: STEPS.map((step) => step.pose),
89 reducedMotion: window.matchMedia('(prefers-reduced-motion: reduce)').matches,
90 getEntryProgress: () => entryProgress(sectionRef.current),
91 });
92 if (cancelled) {
93 handle.dispose();
94 return;
95 }
96 handleRef.current = handle;
97 handle.show(activeRef.current);
98 setReady(true);
99 visibility = new IntersectionObserver(([v]) => handle?.setActive(v.intersectionRatio >= 0.3), { threshold: 0.3 });
100 visibility.observe(container);
101 } catch {
102 setFallback(true);
103 }
104 },
105 { rootMargin: '100% 0px' }
106 );
107 loader.observe(container);
108
109 return () => {
110 cancelled = true;
111 loader.disconnect();
112 visibility?.disconnect();
113 handle?.dispose();
114 handleRef.current = null;
115 };
116 }, [sectionRef]);
117
118 return (
119 <div className={`how-canvas${ready ? ' ready' : ''}`} ref={containerRef}>
120 {fallback && (
121 <IPhoneFrame
122 className="how-fallback"
123 media={STEPS[active].screen}
124 alt={STEPS[active].caption}
125 />
126 )}
127 </div>
128 );
129}
130
131export default function HowItWorks() {
132 const [active, setActive] = useState(0);
133 const [narrow, setNarrow] = useState(false);
134 const sectionRef = useRef<HTMLElement>(null);
135 const stepsRef = useRef<HTMLOListElement>(null);
136 const stepRefs = useRef<(HTMLLIElement | null)[]>([]);
137
138 useEffect(() => {
139 const query = window.matchMedia('(max-width: 900px)');
140 const sync = () => setNarrow(query.matches);
141 sync();
142 query.addEventListener('change', sync);
143 return () => query.removeEventListener('change', sync);
144 }, []);
145
146 useEffect(() => {
147 // Wide screens: a step becomes active as it scrolls across the middle of the
148 // viewport. Narrow screens: the steps are a swipeable carousel under the phone,
149 // and the card that's mostly in view is the active one.
150 const observer = new IntersectionObserver(
151 (entries) => {
152 entries.forEach((entry) => {
153 if (entry.isIntersecting) setActive(Number((entry.target as HTMLElement).dataset.index));
154 });
155 },
156 narrow ? { root: stepsRef.current, threshold: 0.6 } : { rootMargin: '-50% 0px -50% 0px' }
157 );
158 stepRefs.current.forEach((step) => step && observer.observe(step));
159 return () => observer.disconnect();
160 }, [narrow]);
161
162 const showStep = (index: number) => {
163 const list = stepsRef.current;
164 const step = stepRefs.current[index];
165 if (!list || !step) return;
166 list.scrollTo({ left: step.offsetLeft - (list.clientWidth - step.clientWidth) / 2, behavior: 'smooth' });
167 };
168
169 return (
170 <section className="how night" id="how" ref={sectionRef} aria-labelledby="how-heading">
171 <div className="how-glow" aria-hidden="true" />
172 <div className="wrap how-grid">
173 <header className="how-head">
174 <div className="eyebrow">How it works</div>
175 <h2 id="how-heading">Capture, transcribe, understand.</h2>
176 <p>From a few spoken words to an editable, searchable note in three steps.</p>
177 </header>
178
179 <div className="how-stage">
180 <div className="how-sticky">
181 <PhoneStage active={active} sectionRef={sectionRef} />
182 <p className="how-caption" aria-live="polite">
183 <span className="how-caption-dot" aria-hidden="true" />
184 Real app · {STEPS[active].caption}
185 </p>
186 </div>
187 </div>
188
189 <ol className="how-steps" ref={stepsRef}>
190 {STEPS.map((step, index) => (
191 <li
192 key={step.title}
193 ref={(element) => {
194 stepRefs.current[index] = element;
195 }}
196 data-index={index}
197 className={`how-step${index === active ? ' on' : ''}`}
198 >
199 <div className="how-step-card">
200 <div className="how-step-label">
201 <span className="how-step-icon">{step.icon}</span>
202 {step.label}
203 </div>
204 <h3>{step.title}</h3>
205 <p>{step.body}</p>
206 </div>
207 </li>
208 ))}
209 </ol>
210
211 <div className="how-dots" aria-label="Choose a step">
212 {STEPS.map((step, index) => (
213 <button
214 key={step.title}
215 type="button"
216 className={index === active ? 'on' : ''}
217 aria-label={`${step.label}: ${step.title}`}
218 aria-current={index === active ? 'step' : undefined}
219 onClick={() => showStep(index)}
220 />
221 ))}
222 </div>
223 </div>
224 </section>
225 );
226}