Skip to content

Commit 4306204

Browse files
committed
use show
1 parent 08a0e19 commit 4306204

1 file changed

Lines changed: 96 additions & 89 deletions

File tree

  • frontend/src/ts/components/layout/header

frontend/src/ts/components/layout/header/Nav.tsx

Lines changed: 96 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import { getSnapshot, MiniSnapshot } from "../../../states/snapshot";
2626
import { getFocus } from "../../../states/test";
2727
import { cn } from "../../../utils/cn";
2828
import { getLevelFromTotalXp } from "../../../utils/levels";
29-
import { AnimeSwitch } from "../../common/anime";
30-
import { AnimeMatch } from "../../common/anime/AnimeMatch";
29+
import { Anime } from "../../common/anime";
30+
import { AnimePresence } from "../../common/anime/AnimePresence";
3131
import { Button } from "../../common/Button";
3232
import { NotificationBubble } from "../../common/NotificationBubble";
3333
import { User } from "../../common/User";
@@ -86,8 +86,6 @@ export function Nav(): JSXElement {
8686
const showLoginButton = (): boolean =>
8787
serverConfig.data?.users.signUp ?? true;
8888

89-
const snap = () => getSnapshot();
90-
9189
return (
9290
<nav class={cn("z-5 flex w-full items-center gap-1 md:gap-2")}>
9391
<Button
@@ -171,92 +169,101 @@ export function Nav(): JSXElement {
171169
show={showAlertsNotificationBubble()}
172170
/>
173171
</Button>
174-
<AnimeSwitch exitBeforeEnter>
175-
<AnimeMatch
176-
when={snap() === undefined}
177-
initial={{ opacity: 0 }}
178-
animate={{ opacity: 1, duration: 125 }}
179-
exit={{ opacity: 0, duration: 125 }}
180-
>
181-
<Show when={showLoginButton()}>
182-
<Button
183-
variant="text"
184-
href="/login"
185-
dataset={{
186-
"data-nav-item": "login",
187-
}}
188-
fa={{
189-
icon: "fa-user",
190-
variant: "regular",
191-
fixedWidth: true,
192-
}}
193-
router-link
194-
class={buttonClass()}
195-
/>
196-
</Show>
197-
</AnimeMatch>
198-
<AnimeMatch
199-
when={snap() !== undefined}
200-
initial={{ opacity: 0 }}
201-
animate={{ opacity: 1, duration: 125 }}
202-
exit={{ opacity: 0, duration: 125 }}
203-
>
204-
<div
205-
ref={accountMenuRef}
206-
class={cn(
207-
"relative",
208-
!getFocus() &&
209-
"hover:**:data-[ui-element='accountMenu']:pointer-events-auto hover:**:data-[ui-element='accountMenu']:opacity-100",
210-
"has-focus-visible:**:data-[ui-element='accountMenu']:pointer-events-auto has-focus-visible:**:data-[ui-element='accountMenu']:opacity-100",
211-
getAccountMenuOpen() &&
212-
"**:data-[ui-element='accountMenu']:pointer-events-auto **:data-[ui-element='accountMenu']:opacity-100",
213-
)}
214-
// oxlint-disable-next-line react/no-unknown-property
215-
on:click={(e: MouseEvent) => {
216-
if (isCoarse()) {
217-
if (e.target instanceof HTMLAnchorElement) {
218-
if (e.target.dataset["navItem"] === "account") {
219-
e.preventDefault();
220-
e.stopPropagation();
221-
}
222-
setAccountMenuOpen((prev) => !prev);
223-
}
224-
}
225-
}}
226-
>
227-
<Button
228-
variant="text"
229-
class={cn(
230-
"h-full",
231-
"hover:**:data-[ui-element='userLevel']:bg-(--themable-button-hover-text)",
232-
{ "opacity-(--nav-focus-opacity)": getFocus() },
233-
)}
234-
href="/account"
235-
router-link
236-
dataset={{
237-
"data-nav-item": "account",
238-
}}
172+
<AnimePresence exitBeforeEnter>
173+
<Show
174+
when={getSnapshot() !== undefined}
175+
fallback={
176+
<Anime
177+
initial={{ opacity: 0 }}
178+
animate={{ opacity: 1, duration: 125 }}
179+
exit={{ opacity: 0, duration: 125 }}
239180
>
240-
<User
241-
user={getSnapshot() as MiniSnapshot}
242-
showAvatar={true}
243-
iconsOnly={true}
244-
hideNameOnSmallScreens={true}
245-
level={getAnimatedLevel()}
246-
showSpinner={getAccountButtonSpinner()}
247-
showNotificationBubble={showFriendsNotificationBubble()}
248-
fontClass="text-em-xs"
249-
/>
250-
</Button>
251-
<AccountMenu
252-
showFriendsNotificationBubble={showFriendsNotificationBubble()}
253-
/>
254-
</div>
255-
<div class="relative">
256-
<AccountXpBar />
257-
</div>
258-
</AnimeMatch>
259-
</AnimeSwitch>
181+
<Show when={showLoginButton()}>
182+
<Button
183+
variant="text"
184+
href="/login"
185+
dataset={{
186+
"data-nav-item": "login",
187+
}}
188+
fa={{
189+
icon: "fa-user",
190+
variant: "regular",
191+
fixedWidth: true,
192+
}}
193+
router-link
194+
class={buttonClass()}
195+
/>
196+
</Show>
197+
</Anime>
198+
}
199+
>
200+
{(_) => {
201+
const snap = getSnapshot() as MiniSnapshot;
202+
return (
203+
<Anime
204+
initial={{ opacity: 0 }}
205+
animate={{ opacity: 1, duration: 125 }}
206+
exit={{ opacity: 0, duration: 125 }}
207+
>
208+
<div
209+
ref={accountMenuRef}
210+
class={cn(
211+
"relative",
212+
!getFocus() &&
213+
"hover:**:data-[ui-element='accountMenu']:pointer-events-auto hover:**:data-[ui-element='accountMenu']:opacity-100",
214+
"has-focus-visible:**:data-[ui-element='accountMenu']:pointer-events-auto has-focus-visible:**:data-[ui-element='accountMenu']:opacity-100",
215+
getAccountMenuOpen() &&
216+
"**:data-[ui-element='accountMenu']:pointer-events-auto **:data-[ui-element='accountMenu']:opacity-100",
217+
)}
218+
// oxlint-disable-next-line react/no-unknown-property
219+
on:click={(e: MouseEvent) => {
220+
if (isCoarse()) {
221+
if (e.target instanceof HTMLAnchorElement) {
222+
if (e.target.dataset["navItem"] === "account") {
223+
e.preventDefault();
224+
e.stopPropagation();
225+
}
226+
setAccountMenuOpen((prev) => !prev);
227+
}
228+
}
229+
}}
230+
>
231+
<Button
232+
variant="text"
233+
class={cn(
234+
"h-full",
235+
"hover:**:data-[ui-element='userLevel']:bg-(--themable-button-hover-text)",
236+
{ "opacity-(--nav-focus-opacity)": getFocus() },
237+
)}
238+
href="/account"
239+
router-link
240+
dataset={{
241+
"data-nav-item": "account",
242+
}}
243+
>
244+
<User
245+
user={snap}
246+
showAvatar={true}
247+
iconsOnly={true}
248+
hideNameOnSmallScreens={true}
249+
level={getAnimatedLevel()}
250+
showSpinner={getAccountButtonSpinner()}
251+
showNotificationBubble={showFriendsNotificationBubble()}
252+
fontClass="text-em-xs"
253+
/>
254+
</Button>
255+
<AccountMenu
256+
showFriendsNotificationBubble={showFriendsNotificationBubble()}
257+
/>
258+
</div>
259+
<div class="relative">
260+
<AccountXpBar />
261+
</div>
262+
</Anime>
263+
);
264+
}}
265+
</Show>
266+
</AnimePresence>
260267
</nav>
261268
);
262269
}

0 commit comments

Comments
 (0)