-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8ea716
commit f32aa38
Showing
14 changed files
with
323 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { LogOut } from "lucide-react"; | ||
import { useEffect } from "react"; | ||
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuTrigger } from "../ui/dropdown-menu"; | ||
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar"; | ||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip"; | ||
import { Button } from "../ui/button"; | ||
import { useAuth } from "@/hooks/auth/use-auth"; | ||
import { useAuthStore } from "@/stores/auth"; | ||
import Logo from "@/assets/logo.svg"; | ||
import { useRouteContext } from "@tanstack/react-router"; | ||
|
||
export function UserNav() { | ||
const { handleLogout } = useAuth(); | ||
const displayName = useAuthStore((state) => state.displayName); | ||
|
||
const routeContext = useRouteContext({ | ||
from: "__root__", | ||
}); | ||
|
||
useEffect(() => { | ||
window.addEventListener("keydown", (e) => { | ||
if (e.key === "q" && (e.ctrlKey || e.metaKey)) { | ||
handleLogout(); | ||
} | ||
}); | ||
|
||
return () => { | ||
window.removeEventListener("keydown", () => {}); | ||
}; | ||
}); | ||
|
||
if (!routeContext.auth.isLoggedIn) return null; | ||
|
||
return ( | ||
<DropdownMenu> | ||
<TooltipProvider disableHoverableContent> | ||
<Tooltip delayDuration={100}> | ||
<TooltipTrigger asChild> | ||
<DropdownMenuTrigger asChild> | ||
<Button variant="outline" className="relative h-8 w-8 rounded-full"> | ||
<Avatar className="h-8 w-8"> | ||
<AvatarImage src={Logo} /> | ||
<AvatarFallback>BR</AvatarFallback> | ||
</Avatar> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
</TooltipTrigger> | ||
<TooltipContent side="bottom">Profile</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
|
||
<DropdownMenuContent className="w-56" align="end" forceMount> | ||
<DropdownMenuLabel className="font-normal"> | ||
<div className="flex flex-col space-y-1"> | ||
<p className="text-sm font-medium leading-none">{displayName}</p> | ||
</div> | ||
</DropdownMenuLabel> | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuGroup> | ||
<DropdownMenuItem className="hover:cursor-pointer" onClick={handleLogout}> | ||
<LogOut className="mr-3 h-4 w-4 text-muted-foreground" /> | ||
<span>Log out</span> | ||
<DropdownMenuShortcut>⇧⌘Q</DropdownMenuShortcut> | ||
</DropdownMenuItem> | ||
</DropdownMenuGroup> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as React from "react" | ||
import * as AvatarPrimitive from "@radix-ui/react-avatar" | ||
|
||
import { cn } from "@/lib/utils" | ||
|
||
const Avatar = React.forwardRef< | ||
React.ElementRef<typeof AvatarPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root> | ||
>(({ className, ...props }, ref) => ( | ||
<AvatarPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full", | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
Avatar.displayName = AvatarPrimitive.Root.displayName | ||
|
||
const AvatarImage = React.forwardRef< | ||
React.ElementRef<typeof AvatarPrimitive.Image>, | ||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image> | ||
>(({ className, ...props }, ref) => ( | ||
<AvatarPrimitive.Image | ||
ref={ref} | ||
className={cn("aspect-square h-full w-full", className)} | ||
{...props} | ||
/> | ||
)) | ||
AvatarImage.displayName = AvatarPrimitive.Image.displayName | ||
|
||
const AvatarFallback = React.forwardRef< | ||
React.ElementRef<typeof AvatarPrimitive.Fallback>, | ||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback> | ||
>(({ className, ...props }, ref) => ( | ||
<AvatarPrimitive.Fallback | ||
ref={ref} | ||
className={cn( | ||
"flex h-full w-full items-center justify-center rounded-full bg-muted", | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName | ||
|
||
export { Avatar, AvatarImage, AvatarFallback } |
Oops, something went wrong.