Debian Codegraph @

web/src/app/transition.js

raw
1 // Fade transitions between the app and the auth pages (login/signup/reset): fade #root out, then
2 // navigate client-side (fading back in) or full-reload (the splash fades the next page in).
3
4 const FADE_MS = 150;
5 const rootNode = () => document.getElementById("root");
6
7 // Fade #root out, resolving when done. Exported so callers can await it before their own
8 // teardown + reload (e.g. resetAndRedirect wiping IndexedDB).
9 export const fadeOut = () =>
10 new Promise((resolve) => {
11 const node = rootNode();
12 if (!node) {
13 resolve();
14 return;
15 }
16 node.style.transition = `opacity ${FADE_MS}ms ease-out`;
17 node.style.opacity = "0";
18 setTimeout(resolve, FADE_MS);
19 });
20
21 // Fade #root back in, then strip the inline styles (a lingering `transition` would animate future
22 // opacity changes). setTimeout, not rAF, so a backgrounded tab can't strand #root at opacity 0.
23 const fadeInRoot = () => {
24 const node = rootNode();
25 if (!node) {
26 return;
27 }
28 node.style.opacity = "1";
29 setTimeout(() => {
30 node.style.transition = "";
31 node.style.opacity = "";
32 }, FADE_MS);
33 };
34
35 // Fade out, navigate client-side, fade the new page in (app -> login/signup, no reload).
36 export const fadeNavigate = (navigate, to) => {
37 fadeOut().then(() => {
38 navigate(to);
39 fadeInRoot();
40 });
41 };
42
43 // Fade out, then full-reload to `url` (login/signup -> app needs a reload for the per-user DB).
44 // The splash fades it back in.
45 export const fadeReload = (url) => {
46 fadeOut().then(() => {
47 window.location.href = url;
48 });
49 };