1+ import { useAuth } from "@/hooks/auth" ;
2+ import { Dialog , DialogClose , DialogContent , DialogTrigger } from "@radix-ui/react-dialog" ;
13import { Link } from "@tanstack/react-router" ;
4+ import { FC } from "react" ;
5+ import { Modal } from "./modal/Modal" ;
6+ import { FaSteam } from "react-icons/fa" ;
7+ import { useGuestAuth } from "@/api/auth" ;
8+ import { Avatar } from "./auth/Avatar" ;
9+ import { LuLogOut } from "react-icons/lu" ;
10+ import { toast } from "sonner" ;
211
312export const Navbar = ( ) => {
413 return (
514 < >
6- < div className = "w-full bg-primary fixed sm:relative" >
7- < div className = "flex items-stretch gap-2 h-full" >
8- < div className = "px-1 max-h-full min-w-2 flex items-center gap-2 bg-secondary" >
9- < div className = "size-8 rounded-md" >
10- < img src = "/lock.code.png" alt = "lock.code" className = "w-full h-full object-contain" />
15+ < div className = "w-full bg-primary fixed sm:relative flex justify-between items-center" >
16+ < div className = "flex items-stretch gap-2 h-full" >
17+ < div className = "px-1 max-h-full min-w-2 flex items-center gap-2 bg-secondary" >
18+ < div className = "size-8 rounded-md" >
19+ < img src = "/lock.code.png" alt = "lock.code" className = "w-full h-full object-contain" />
20+ </ div >
1121 </ div >
22+ < Link to = "/" className = "text-accent text-base hover:underline py-2 block" >
23+ < span > code</ span >
24+ < span className = "text-secondary" > .</ span >
25+ < span > fishing</ span >
26+ </ Link >
27+ </ div >
28+ < div className = "flex items-center h-full gap-2 flex-1 justify-end" >
29+ < UserProfile />
1230 </ div >
13- < Link to = "/" className = "text-accent text-base hover:underline py-2 block" >
14- < span > code</ span >
15- < span className = "text-secondary" > .</ span >
16- < span > fishing</ span >
17- </ Link >
18- </ div >
1931 </ div >
2032 < div className = "h-12 w-full sm:hidden" />
2133 </ >
2234 )
2335} ;
36+
37+ export const UserProfile : FC < { } > = ( ) => {
38+ const { isAuthenticated, logout, user } = useAuth ( ) ;
39+
40+ if ( ! isAuthenticated ) {
41+ return (
42+ < LoginModal />
43+ ) ;
44+ }
45+
46+ return (
47+ < div className = "flex items-center gap-1" >
48+ < div className = "flex items-center gap-1" >
49+ < Avatar src = { user ?. avatar } seed = { user ?. user_id } />
50+ < span > { user ?. name } </ span >
51+ </ div >
52+ < button className = "button flex items-center gap-1" onClick = { logout } >
53+ < LuLogOut className = "size-4" />
54+ < span > Logout</ span >
55+ </ button >
56+ </ div >
57+ ) ;
58+ } ;
59+
60+ export const LoginModal : FC < { } > = ( ) => {
61+ return (
62+ < Dialog >
63+ < DialogTrigger asChild >
64+ < button className = "button" >
65+ < span > Login</ span >
66+ </ button >
67+ </ DialogTrigger >
68+ < Modal size = "medium" >
69+ < LoginModalContent />
70+ </ Modal >
71+ </ Dialog >
72+ )
73+ }
74+
75+ export const LoginModalContent : FC < { } > = ( ) => {
76+ const { login } = useAuth ( ) ;
77+ const { mutate : guestAuth } = useGuestAuth ( {
78+ onSuccess : ( data ) => {
79+ login ( data . token , data . user ) ;
80+ toast . success ( "Logged in as guest" ) ;
81+ }
82+ } ) ;
83+
84+ return (
85+ < div className = "flex flex-wrap gap-4" >
86+ < div className = "flex flex-col gap-2 sm:w-[calc(50%-1rem)]" >
87+ < h2 > Sign in as Guest</ h2 >
88+ < p className = "text-secondary" > Click here to continue as an anonymous user.</ p >
89+ < DialogClose asChild >
90+ < button className = "button" onClick = { ( ) => guestAuth ( undefined , undefined ) } >
91+ < span > Continue as Guest</ span >
92+ </ button >
93+ </ DialogClose >
94+ </ div >
95+ < div className = "flex flex-col gap-2 sm:w-[calc(50%-1rem)]" >
96+ < h2 > Sign in with Steam</ h2 >
97+ < p className = "text-secondary" > Click here to sign in with your Steam account.</ p >
98+ < button className = "button flex items-center justify-center gap-2" disabled >
99+ < FaSteam className = "size-4" />
100+ < span > Sign in with Steam</ span >
101+ </ button >
102+ </ div >
103+ </ div >
104+ )
105+ }
0 commit comments