Branchwell

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

1'use client';
2
3import { useEffect, useRef, useState } from 'react';
4import { Play, X } from 'lucide-react';
5import { sendGAEvent } from '@/app/utils/analytics';
6import { MARKETING_FILM, filmSrc, formatTime } from './media';
7
8/**
9 * The marketing film as the hero centrepiece. It shows the film's poster
10 * until someone presses play, then plays from R2 in place; closing it
11 * returns to the still. The frame tilts back in perspective and stands up as the page scrolls.
12 */
13export default function HeroFilm() {
14 const stageRef = useRef<HTMLDivElement>(null);
15 const [watching, setWatching] = useState(false);
16
17 // Scroll-linked tilt: --tilt goes 1 → 0 as the frame rises into view.
18 useEffect(() => {
19 const stage = stageRef.current;
20 if (!stage || window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
21 stage?.style.setProperty('--tilt', '0');
22 return;
23 }
24 let frame = 0;
25 const update = () => {
26 frame = 0;
27 const rect = stage.getBoundingClientRect();
28 const viewport = window.innerHeight;
29 const progress = Math.min(1, Math.max(0, (viewport - rect.top) / (viewport * 0.75)));
30 stage.style.setProperty('--tilt', (1 - progress).toFixed(4));
31 };
32 const onScroll = () => {
33 if (!frame) frame = requestAnimationFrame(update);
34 };
35 update();
36 window.addEventListener('scroll', onScroll, { passive: true });
37 window.addEventListener('resize', onScroll);
38 return () => {
39 cancelAnimationFrame(frame);
40 window.removeEventListener('scroll', onScroll);
41 window.removeEventListener('resize', onScroll);
42 };
43 }, []);
44
45 const watch = () => {
46 setWatching(true);
47 sendGAEvent('film_play_sound', { film: 'marketing' });
48 };
49
50 return (
51 <div className="hero-film" ref={stageRef}>
52 <div className="hero-film-glow" aria-hidden="true" />
53 <figure className={`film-frame ${watching ? 'watching' : 'ambient'}`}>
54 <div className="film-screen">
55 {watching ? (
56 <>
57 {/* Captions are burned into the picture. */}
58 <video
59 src={filmSrc(MARKETING_FILM)}
60 poster={MARKETING_FILM.poster}
61 title="What is Jotley? A free voice notes app for Mac, iPhone and iPad"
62 aria-label="What is Jotley? A free voice notes app for Mac, iPhone and iPad"
63 controls
64 autoPlay
65 playsInline
66 />
67 <button type="button" className="film-close" onClick={() => setWatching(false)} aria-label="Close the film">
68 <X size={17} aria-hidden="true" />
69 </button>
70 </>
71 ) : (
72 <>
73 {/* eslint-disable-next-line @next/next/no-img-element */}
74 <img
75 src={MARKETING_FILM.poster}
76 alt="What is Jotley? A free voice notes app for Mac, iPhone and iPad"
77 fetchPriority="high"
78 onClick={watch}
79 />
80 <div className="film-glass" aria-hidden="true" />
81 <button type="button" className="film-cta" onClick={watch}>
82 <span className="film-cta-icon"><Play size={16} fill="currentColor" aria-hidden="true" /></span>
83 <span>Play the film</span>
84 <span className="film-cta-time">{formatTime(MARKETING_FILM.duration)}</span>
85 </button>
86 </>
87 )}
88 </div>
89 </figure>
90 </div>
91 );
92}