2025-01-07 18:27:42 +00:00
|
|
|
'use client';
|
|
|
|
|
|
2024-08-28 04:00:59 +00:00
|
|
|
import {
|
|
|
|
|
CodeIcon,
|
|
|
|
|
Laptop,
|
2025-01-19 20:52:13 +00:00
|
|
|
LogOut,
|
2024-08-28 04:00:59 +00:00
|
|
|
Moon,
|
|
|
|
|
Settings,
|
|
|
|
|
Sun
|
|
|
|
|
} from "lucide-react"
|
|
|
|
|
import { Button } from "@/components/ui/button"
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuGroup,
|
2025-01-19 20:52:13 +00:00
|
|
|
DropdownMenuItem,
|
2024-08-28 04:00:59 +00:00
|
|
|
DropdownMenuPortal,
|
|
|
|
|
DropdownMenuRadioGroup,
|
|
|
|
|
DropdownMenuRadioItem,
|
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
|
DropdownMenuSub,
|
|
|
|
|
DropdownMenuSubContent,
|
|
|
|
|
DropdownMenuSubTrigger,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from "@/components/ui/dropdown-menu"
|
|
|
|
|
import { useTheme } from "next-themes"
|
|
|
|
|
import { useMemo } from "react"
|
|
|
|
|
import { KeymapType } from "@/lib/types"
|
2024-09-03 01:46:43 +00:00
|
|
|
import { cn } from "@/lib/utils"
|
|
|
|
|
import { useKeymapType } from "@/hooks/useKeymapType"
|
2024-10-28 17:06:51 +00:00
|
|
|
import { NEXT_PUBLIC_SOURCEBOT_VERSION } from "@/lib/environment.client";
|
2025-01-19 20:52:13 +00:00
|
|
|
import { useSession } from "next-auth/react";
|
|
|
|
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
|
|
|
import { signOut } from "next-auth/react"
|
|
|
|
|
|
2024-08-28 04:00:59 +00:00
|
|
|
|
|
|
|
|
interface SettingsDropdownProps {
|
2024-09-03 01:46:43 +00:00
|
|
|
menuButtonClassName?: string;
|
2024-08-28 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const SettingsDropdown = ({
|
2024-09-03 01:46:43 +00:00
|
|
|
menuButtonClassName,
|
2024-08-28 04:00:59 +00:00
|
|
|
}: SettingsDropdownProps) => {
|
|
|
|
|
|
|
|
|
|
const { theme: _theme, setTheme } = useTheme();
|
2025-01-19 20:52:13 +00:00
|
|
|
const [keymapType, setKeymapType] = useKeymapType();
|
|
|
|
|
const { data: session } = useSession();
|
2024-09-03 01:46:43 +00:00
|
|
|
|
2024-08-28 04:00:59 +00:00
|
|
|
const theme = useMemo(() => {
|
|
|
|
|
return _theme ?? "light";
|
|
|
|
|
}, [_theme]);
|
|
|
|
|
|
|
|
|
|
const ThemeIcon = useMemo(() => {
|
|
|
|
|
switch (theme) {
|
|
|
|
|
case "light":
|
|
|
|
|
return <Sun className="h-4 w-4 mr-2" />;
|
|
|
|
|
case "dark":
|
|
|
|
|
return <Moon className="h-4 w-4 mr-2" />;
|
|
|
|
|
case "system":
|
|
|
|
|
return <Laptop className="h-4 w-4 mr-2" />;
|
|
|
|
|
default:
|
|
|
|
|
return <Laptop className="h-4 w-4 mr-2" />;
|
|
|
|
|
}
|
|
|
|
|
}, [theme]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
2024-09-03 01:46:43 +00:00
|
|
|
<Button variant="outline" size="icon" className={cn(menuButtonClassName)}>
|
2024-08-28 04:00:59 +00:00
|
|
|
<Settings className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
</DropdownMenuTrigger>
|
2025-01-19 20:52:13 +00:00
|
|
|
<DropdownMenuContent className="w-64">
|
|
|
|
|
{session?.user && (
|
|
|
|
|
<DropdownMenuGroup>
|
|
|
|
|
<div className="flex flex-row items-center gap-1 p-2">
|
|
|
|
|
<Avatar>
|
|
|
|
|
<AvatarImage
|
|
|
|
|
src={session.user.image ?? ""}
|
|
|
|
|
/>
|
|
|
|
|
<AvatarFallback>
|
|
|
|
|
{session.user.name && session.user.name.length > 0 ? session.user.name[0] : 'U'}
|
|
|
|
|
</AvatarFallback>
|
|
|
|
|
</Avatar>
|
|
|
|
|
<p className="text-sm font-medium text-ellipsis">{session.user.email ?? "User"}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
onClick={() => {
|
2025-02-12 21:51:44 +00:00
|
|
|
signOut({
|
|
|
|
|
redirectTo: "/login",
|
|
|
|
|
});
|
2025-01-19 20:52:13 +00:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<LogOut className="mr-2 h-4 w-4" />
|
|
|
|
|
<span>Log out</span>
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
|
</DropdownMenuGroup>
|
|
|
|
|
)}
|
2024-08-28 04:00:59 +00:00
|
|
|
<DropdownMenuGroup>
|
|
|
|
|
<DropdownMenuSub>
|
|
|
|
|
<DropdownMenuSubTrigger>
|
|
|
|
|
{ThemeIcon}
|
|
|
|
|
<span>Theme</span>
|
|
|
|
|
</DropdownMenuSubTrigger>
|
|
|
|
|
<DropdownMenuPortal>
|
|
|
|
|
<DropdownMenuSubContent>
|
|
|
|
|
<DropdownMenuRadioGroup value={theme} onValueChange={setTheme}>
|
|
|
|
|
<DropdownMenuRadioItem value="light">
|
|
|
|
|
Light
|
|
|
|
|
</DropdownMenuRadioItem>
|
|
|
|
|
<DropdownMenuRadioItem value="dark">
|
|
|
|
|
Dark
|
|
|
|
|
</DropdownMenuRadioItem>
|
|
|
|
|
<DropdownMenuRadioItem value="system">
|
|
|
|
|
System
|
|
|
|
|
</DropdownMenuRadioItem>
|
|
|
|
|
</DropdownMenuRadioGroup>
|
|
|
|
|
</DropdownMenuSubContent>
|
|
|
|
|
</DropdownMenuPortal>
|
|
|
|
|
</DropdownMenuSub>
|
|
|
|
|
<DropdownMenuSub>
|
|
|
|
|
<DropdownMenuSubTrigger>
|
|
|
|
|
<CodeIcon className="h-4 w-4 mr-2" />
|
|
|
|
|
<span>Code navigation</span>
|
|
|
|
|
</DropdownMenuSubTrigger>
|
|
|
|
|
<DropdownMenuPortal>
|
|
|
|
|
<DropdownMenuSubContent>
|
2024-09-03 01:46:43 +00:00
|
|
|
<DropdownMenuRadioGroup value={keymapType} onValueChange={(value) => setKeymapType(value as KeymapType)}>
|
2024-08-28 04:00:59 +00:00
|
|
|
<DropdownMenuRadioItem value="default">
|
|
|
|
|
Default
|
|
|
|
|
</DropdownMenuRadioItem>
|
|
|
|
|
<DropdownMenuRadioItem value="vim">
|
|
|
|
|
Vim
|
|
|
|
|
</DropdownMenuRadioItem>
|
|
|
|
|
</DropdownMenuRadioGroup>
|
|
|
|
|
</DropdownMenuSubContent>
|
|
|
|
|
</DropdownMenuPortal>
|
|
|
|
|
</DropdownMenuSub>
|
|
|
|
|
</DropdownMenuGroup>
|
2025-01-19 20:52:13 +00:00
|
|
|
<DropdownMenuSeparator />
|
|
|
|
|
<div className="px-2 py-1 text-sm text-muted-foreground">
|
|
|
|
|
version: {NEXT_PUBLIC_SOURCEBOT_VERSION}
|
|
|
|
|
</div>
|
2024-08-28 04:00:59 +00:00
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
)
|
|
|
|
|
}
|