-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
43 lines (37 loc) · 1.22 KB
/
App.tsx
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
import React, { useState, useRef } from "react";
import { flushSync } from "react-dom";
import { emojis, EmojiItem } from "./data";
import Chrome from "./components/Chrome";
import List from './components/List';
import Details from "./components/Details/Details";
export default function App() {
const [nav, setNav] = useState("/list");
const [emoji, setEmoji] = useState<EmojiItem | null>(null);
const onEmojiClick = (emoji: EmojiItem, origin: HTMLElement) => {
const img = origin.querySelector('.img') as HTMLElement;
const name = origin.querySelector('.name') as HTMLElement;
img.style.viewTransitionName = "emoji-img"
name.style.viewTransitionName = "emoji-name"
document.startViewTransition(() => {
flushSync(() => {
setNav(`/details/${emoji.name}`);
setEmoji(() => emoji);
});
});
};
const onClickBack = (ev) => {
document.startViewTransition(() => {
flushSync(() => {
setNav("/list");
setEmoji(null);
});
});
}
return (
<Chrome onClickBack={onClickBack}>
{nav === "/list" &&
<List emojis={emojis} onItemClick={onEmojiClick} />}
{/\/details\/.*?/.test(nav) && <Details emoji={emoji} />}
</Chrome>
);
}