fix: sidebar redesign and api key validation
Signed-off-by: Varun <varun@skcript.com>
This commit is contained in:
1 parent
15f90121a1
commit
937f64a57e
6 files changed
+527
-217
No files matched your search
@@ -1,70 +1,114 @@
|
||||
import React from "react";
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Button } from "@/components/ui/button";
|
||||
import Link from "next/link";
|
||||
import { useConfig } from "@/contexts/ConfigContext";
|
||||
import { logoutUser } from "@/handlers/api/user.handler"
|
||||
import { logoutUser } from "@/handlers/api/user.handler";
|
||||
import { useCurrentUser } from "@/contexts/CurrentUserContext";
|
||||
import { useToast } from "../ui/use-toast";
|
||||
import { HandshakeIcon } from "lucide-react";
|
||||
import { useTheme } from "next-themes";
|
||||
import { Tooltip } from "@/components/ui/tooltip";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { HandshakeIcon, Server, Globe, LogOut, Moon, Sun, User, Settings } from "lucide-react";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
export default function ProfileInfo() {
|
||||
const { updateContext, ...user } = useCurrentUser()
|
||||
const { updateContext, ...user } = useCurrentUser();
|
||||
const { immichURL, exImmichUrl, version } = useConfig();
|
||||
const { theme, setTheme } = useTheme();
|
||||
const toast = useToast();
|
||||
const router = useRouter();
|
||||
|
||||
const handleLogout = () => logoutUser()
|
||||
.then(() => {
|
||||
updateContext(null)
|
||||
}).catch((error) => {
|
||||
toast.toast({
|
||||
title: "Error",
|
||||
description: error.message,
|
||||
})
|
||||
})
|
||||
|
||||
const handleLogout = () =>
|
||||
logoutUser()
|
||||
.then(() => updateContext(null))
|
||||
.catch((error) => {
|
||||
toast.toast({ title: "Error", description: error.message });
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col gap-2 text-xs text-center py-2">
|
||||
<p className="text-muted-foreground font-mono">Connected to (External)</p>
|
||||
<Link href={exImmichUrl} target="_blank" className="font-mono">
|
||||
{exImmichUrl}
|
||||
</Link>
|
||||
<p className="text-muted-foreground font-mono">Connected to (Internal)</p>
|
||||
<Link href={immichURL} target="_blank" className="font-mono">
|
||||
{immichURL}
|
||||
</Link>
|
||||
{user && (
|
||||
<>
|
||||
<p className="text-sm">{user?.name}</p>
|
||||
<div className="flex items-center justify-between gap-2 px-2">
|
||||
{!user.isUsingAPIKey && (
|
||||
<Button variant="destructive" className="h-6 flex-1 text-xs" onClick={handleLogout}>
|
||||
Log Out
|
||||
</Button>
|
||||
)}
|
||||
<Button asChild variant="secondary" className="h-6 flex-1 text-xs flex items-center justify-center gap-2" onClick={handleLogout}>
|
||||
<Link href="https://buymeacoffee.com/varunraj" target="_blank">
|
||||
<HandshakeIcon className="w-4 h-4" />
|
||||
{/* Connection info */}
|
||||
<div className="border-t px-3 py-2 space-y-1">
|
||||
<Tooltip content={`External: ${exImmichUrl}`}>
|
||||
<div className="flex items-center gap-1.5 text-[10px] text-muted-foreground">
|
||||
<Globe className="h-3 w-3 shrink-0" />
|
||||
<Link href={exImmichUrl} target="_blank" className="font-mono truncate hover:text-foreground transition-colors">
|
||||
{exImmichUrl}
|
||||
</Link>
|
||||
</div>
|
||||
</Tooltip>
|
||||
<Tooltip content={`Internal: ${immichURL}`}>
|
||||
<div className="flex items-center gap-1.5 text-[10px] text-muted-foreground">
|
||||
<Server className="h-3 w-3 shrink-0" />
|
||||
<Link href={immichURL} target="_blank" className="font-mono truncate hover:text-foreground transition-colors">
|
||||
{immichURL}
|
||||
</Link>
|
||||
</div>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
{/* User dropdown */}
|
||||
{user && (
|
||||
<div className="border-t px-2 py-2">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="flex items-center gap-2 w-full px-2 py-1.5 rounded-lg hover:bg-muted transition-colors text-left">
|
||||
<div className="h-7 w-7 rounded-full bg-primary/10 flex items-center justify-center shrink-0">
|
||||
<User className="h-3.5 w-3.5 text-primary" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium truncate">{user.name}</p>
|
||||
<p className="text-[10px] text-muted-foreground truncate">{user.email}</p>
|
||||
</div>
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="top" align="start" className="w-52">
|
||||
<DropdownMenuLabel className="text-xs font-normal text-muted-foreground">{user.email}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={() => setTheme(theme === "light" ? "dark" : "light")} className="cursor-pointer">
|
||||
{theme === "light" ? <Moon className="h-4 w-4 mr-2" /> : <Sun className="h-4 w-4 mr-2" />}
|
||||
{theme === "light" ? "Dark Mode" : "Light Mode"}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => router.push("/settings")} className="cursor-pointer">
|
||||
<Settings className="h-4 w-4 mr-2" />
|
||||
Settings
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem asChild className="cursor-pointer">
|
||||
<Link href="https://buymeacoffee.com/varunraj" target="_blank">
|
||||
<HandshakeIcon className="h-4 w-4 mr-2" />
|
||||
Support
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="border-t text-muted-foreground text-xs py-2 flex justify-between items-center px-2">
|
||||
</DropdownMenuItem>
|
||||
{!user.isUsingAPIKey && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={handleLogout} className="cursor-pointer text-destructive focus:text-destructive">
|
||||
<LogOut className="h-4 w-4 mr-2" />
|
||||
Log Out
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Footer */}
|
||||
<div className="border-t text-muted-foreground text-[10px] py-1.5 flex justify-between items-center px-3">
|
||||
<p>
|
||||
Made with <span className="text-red-500">♥</span> by{" "}
|
||||
<Link
|
||||
target="_blank"
|
||||
href="https://x.com/zathvarun"
|
||||
className="text-primary"
|
||||
>
|
||||
<Link target="_blank" href="https://x.com/zathvarun" className="text-primary">
|
||||
@zathvarun
|
||||
</Link>
|
||||
</p>
|
||||
<Link target="_blank" href={`https://github.com/varun-raj/immich-power-tools/releases/tag/v${version}`}>
|
||||
<Link target="_blank" href={`https://github.com/varun-raj/immich-power-tools/releases/tag/v${version}`} className="font-mono">
|
||||
v{version}
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import Link from "next/link";
|
||||
|
||||
import { sidebarNavs } from "@/config/constants/sidebarNavs";
|
||||
import { sidebarGroups } from "@/config/constants/sidebarNavs";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import ProfileInfo from "./ProfileInfo";
|
||||
|
||||
const ThemeSwitcher = dynamic(() => import("@/components/shared/ThemeSwitcher"), {
|
||||
ssr: false,
|
||||
});
|
||||
const ProfileInfo = dynamic(() => import("./ProfileInfo"), { ssr: false });
|
||||
|
||||
export default function Sidebar() {
|
||||
const router = useRouter();
|
||||
@@ -29,24 +26,32 @@ export default function Sidebar() {
|
||||
/>
|
||||
<span className="">Immich Power Tools</span>
|
||||
</Link>
|
||||
<ThemeSwitcher />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<nav className="grid items-start px-2 text-sm font-medium lg:px-4">
|
||||
{sidebarNavs.map((nav) => (
|
||||
<Link
|
||||
key={nav.title}
|
||||
href={nav.link}
|
||||
className={cn(
|
||||
"flex items-center gap-3 rounded-lg py-2 text-muted-foreground transition-all hover:text-primary",
|
||||
{
|
||||
"text-primary": pathname === nav.link,
|
||||
}
|
||||
)}
|
||||
>
|
||||
{nav.icon}
|
||||
{nav.title}
|
||||
</Link>
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
<nav className="px-2 lg:px-4 space-y-4 py-2">
|
||||
{sidebarGroups.map((group) => (
|
||||
<div key={group.label}>
|
||||
<p className="text-[10px] font-semibold uppercase tracking-wider text-muted-foreground/60 px-3 mb-1">
|
||||
{group.label}
|
||||
</p>
|
||||
<div className="space-y-0.5">
|
||||
{group.items.map((nav) => (
|
||||
<Link
|
||||
key={nav.title}
|
||||
href={nav.link}
|
||||
className={cn(
|
||||
"flex items-center gap-3 rounded-lg py-1.5 px-3 text-sm text-muted-foreground transition-all hover:text-primary",
|
||||
{
|
||||
"text-primary bg-primary/5 font-medium": pathname === nav.link,
|
||||
}
|
||||
)}
|
||||
>
|
||||
{nav.icon}
|
||||
{nav.title}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user