-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
64 lines (57 loc) · 2.24 KB
/
Copy pathApp.jsx
File metadata and controls
64 lines (57 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const { useState, useEffect, useCallback } = React;
function App() {
const [lang, setLang] = useState("sv");
const [active, setActive] = useState("top");
const [menuOpen, setMenuOpen] = useState(false);
const scrollTo = useCallback((id) => {
setMenuOpen(false);
const el = document.getElementById(id);
if (!el) return;
const mobileOffset = window.innerWidth <= 720 ? 64 : 0;
window.scrollTo({ top: el.getBoundingClientRect().top + window.scrollY - mobileOffset, behavior: "smooth" });
}, []);
const openSchedule = useCallback(() => {
setMenuOpen(false);
window.open("https://cal.eu/sandstream/quick-chat", "_blank", "noopener,noreferrer");
}, []);
useEffect(() => {
document.body.style.overflow = menuOpen ? "hidden" : "";
return () => { document.body.style.overflow = ""; };
}, [menuOpen]);
useEffect(() => {
const ids = ["top", "about", "work", "music", "roles", "contact"];
const onScroll = () => {
const threshold = window.scrollY + window.innerHeight * 0.15;
let current = ids[0];
for (const id of ids) {
const el = document.getElementById(id);
if (el && el.offsetTop <= threshold) current = id;
}
setActive(current);
};
window.addEventListener("scroll", onScroll, { passive: true });
onScroll();
return () => window.removeEventListener("scroll", onScroll);
}, []);
return (
<div className="page">
<Header lang={lang} setLang={setLang} active={active === "top" ? "" : active} onNav={scrollTo} />
<MobileBar
lang={lang} setLang={setLang}
menuOpen={menuOpen} onToggle={() => setMenuOpen(o => !o)}
onWordmark={() => scrollTo("top")}
/>
<MobileNavOverlay lang={lang} active={active === "top" ? "" : active} onNav={scrollTo} menuOpen={menuOpen} />
<main className="main">
<Hero lang={lang} onSchedule={openSchedule} />
<About lang={lang} />
<Cases lang={lang} />
<Music lang={lang} />
<Roles lang={lang} />
<Contact lang={lang} onSchedule={openSchedule} />
</main>
<FloatingPill lang={lang} onClick={openSchedule} active={active} menuOpen={menuOpen} />
</div>
);
}
ReactDOM.createRoot(document.getElementById("root")).render(<App />);