Skip to content

Commit 3dc0891

Browse files
committed
nav
1 parent 9bf222e commit 3dc0891

1 file changed

Lines changed: 91 additions & 93 deletions

File tree

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

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

Lines changed: 91 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import {
2222
setAnimatedLevel,
2323
} from "../../../states/header";
2424
import { showModal } from "../../../states/modals";
25-
import { getSnapshot } from "../../../states/snapshot";
25+
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 { Anime } from "../../common/anime";
30-
import { AnimePresence } from "../../common/anime/AnimePresence";
29+
import { AnimeSwitch } from "../../common/anime";
30+
import { AnimeMatch } from "../../common/anime/AnimeMatch";
3131
import { Button } from "../../common/Button";
3232
import { NotificationBubble } from "../../common/NotificationBubble";
3333
import { User } from "../../common/User";
@@ -86,6 +86,10 @@ export function Nav(): JSXElement {
8686
const showLoginButton = (): boolean =>
8787
serverConfig.data?.users.signUp ?? true;
8888

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

0 commit comments

Comments
 (0)