Spaces:
Running
Running
Download frontend-v2/src/features/shell/components/TopCommandShell.tsx from TwanAPI/UploadFile: direct link, hf CLI and curl.
- Browser
- Download file 8.54 kB
-
https://huggingface.co/spaces/TwanAPI/UploadFile/resolve/main/frontend-v2/src/features/shell/components/TopCommandShell.tsx
- Command line
-
hf download hf://spaces/TwanAPI/UploadFile/frontend-v2/src/features/shell/components/TopCommandShell.tsx
-
curl -L -o TopCommandShell.tsx https://huggingface.co/spaces/TwanAPI/UploadFile/resolve/main/frontend-v2/src/features/shell/components/TopCommandShell.tsx
8.54 kB
| "use client"; | |
| import React, { useState } from "react"; | |
| import Link from "next/link"; | |
| import { usePathname, useRouter } from "next/navigation"; | |
| import { | |
| Activity, | |
| ArrowRight, | |
| BarChart3, | |
| CloudUpload, | |
| FolderOpen, | |
| Lock, | |
| LogOut, | |
| Menu, | |
| Shield, | |
| Terminal, | |
| X, | |
| } from "lucide-react"; | |
| import { useAuth } from "@/features/auth"; | |
| import { SITE_CONFIG } from "@/shared/config/site"; | |
| import { Button, Pill, Skeleton } from "@/shared/ui"; | |
| const TABS = [ | |
| { href: "/dashboard", label: "Tổng quan", icon: BarChart3 }, | |
| { href: "/explorer", label: "Kho tệp", icon: FolderOpen }, | |
| { href: "/activity", label: "Nhật ký", icon: Activity }, | |
| { href: "/developers", label: "API Docs", icon: Terminal }, | |
| { href: "/admin", label: "Quản trị RBAC", icon: Shield, adminOnly: true }, | |
| ] as const; | |
| export function TopCommandShell({ children }: { children: React.ReactNode }) { | |
| const pathname = usePathname(); | |
| const router = useRouter(); | |
| const { user, loading, healthOk, bucketName, isAdmin, logout } = useAuth(); | |
| const [mobileMenu, setMobileMenu] = useState(false); | |
| if (loading) { | |
| return ( | |
| <div className="min-h-screen flex items-center justify-center bg-drafting-grid p-6"> | |
| <div className="paper-card rounded-2xl p-8 w-full max-w-sm space-y-4"> | |
| <div className="flex items-center gap-3"> | |
| <div className="w-10 h-10 rounded-xl bg-orange-50 border border-orange-200 flex items-center justify-center text-[#c2410c]"> | |
| <CloudUpload className="w-5 h-5 animate-pulse" aria-hidden="true" /> | |
| </div> | |
| <div className="space-y-1.5 flex-1"> | |
| <Skeleton className="h-3.5 w-36" /> | |
| <Skeleton className="h-3 w-48" /> | |
| </div> | |
| </div> | |
| <Skeleton className="h-2.5 w-full" /> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| if (!user) { | |
| return ( | |
| <div className="min-h-screen flex items-center justify-center bg-drafting-grid p-6"> | |
| <div className="paper-card rounded-3xl p-8 max-w-md w-full text-center space-y-5"> | |
| <div className="w-12 h-12 rounded-2xl bg-orange-50 border border-orange-200 flex items-center justify-center text-[#c2410c] mx-auto"> | |
| <Lock className="w-6 h-6" aria-hidden="true" /> | |
| </div> | |
| <div className="space-y-2"> | |
| <h1 className="text-xl font-bold text-[#111318] font-display"> | |
| Vui lòng đăng nhập Studio | |
| </h1> | |
| <p className="text-xs sm:text-sm text-slate-600 leading-relaxed"> | |
| Phiên làm việc chưa được xác thực. Đăng nhập để quản lý kho tệp của bạn. | |
| </p> | |
| </div> | |
| <div className="flex flex-wrap justify-center gap-3"> | |
| <Link | |
| href="/login" | |
| className="px-5 py-2.5 rounded-xl bg-[#c2410c] hover:bg-[#9a3412] text-white font-bold text-sm inline-flex items-center gap-2" | |
| > | |
| <span>Đăng nhập</span> | |
| <ArrowRight className="w-4 h-4" aria-hidden="true" /> | |
| </Link> | |
| <Link | |
| href="/" | |
| className="px-5 py-2.5 rounded-xl bg-white border border-[#e7e5e0] text-[#111318] font-semibold text-sm hover:bg-[#f5f4f0]" | |
| > | |
| Trang chủ | |
| </Link> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| const visibleTabs = TABS.filter((tab) => !("adminOnly" in tab && tab.adminOnly) || isAdmin); | |
| const handleSignOut = async () => { | |
| await logout(); | |
| router.push("/login"); | |
| }; | |
| return ( | |
| <div className="min-h-screen flex flex-col bg-drafting-grid"> | |
| <header className="sticky top-0 z-40 paper-panel border-x-0 border-t-0"> | |
| <div className="max-w-7xl mx-auto px-4 sm:px-8 h-16 flex items-center justify-between gap-4"> | |
| <div className="flex items-center gap-4 min-w-0"> | |
| <Link href="/" className="flex items-center gap-2.5 shrink-0"> | |
| <div className="w-8 h-8 rounded-lg bg-[#c2410c] text-white flex items-center justify-center font-black text-xs font-display"> | |
| UT | |
| </div> | |
| <span className="font-bold text-sm sm:text-base text-[#111318] font-display"> | |
| {SITE_CONFIG.name} | |
| </span> | |
| </Link> | |
| <span className="hidden md:inline text-xs font-mono text-slate-400 border-l border-[#e7e5e0] pl-4 truncate"> | |
| {bucketName} | |
| </span> | |
| </div> | |
| <div className="flex items-center gap-2.5"> | |
| <Pill tone={healthOk ? "emerald" : "amber"} className="hidden sm:inline-flex"> | |
| <span | |
| className={`w-1.5 h-1.5 rounded-full ${healthOk ? "bg-emerald-500" : "bg-amber-500"}`} | |
| aria-hidden="true" | |
| /> | |
| <span>{healthOk ? "Ready" : "Sync"}</span> | |
| </Pill> | |
| <Pill tone={isAdmin ? "vermilion" : "ink"}>@{user.username}</Pill> | |
| <Button | |
| variant="ghost" | |
| size="sm" | |
| onClick={handleSignOut} | |
| className="hidden sm:inline-flex text-rose-700 hover:bg-rose-50" | |
| > | |
| <LogOut className="w-3.5 h-3.5" aria-hidden="true" /> | |
| <span>Thoát</span> | |
| </Button> | |
| <button | |
| type="button" | |
| onClick={() => setMobileMenu((prev) => !prev)} | |
| aria-label={mobileMenu ? "Đóng menu" : "Mở menu"} | |
| className="md:hidden p-2 rounded-lg border border-[#e7e5e0] bg-white text-[#111318]" | |
| > | |
| {mobileMenu ? ( | |
| <X className="w-4 h-4" aria-hidden="true" /> | |
| ) : ( | |
| <Menu className="w-4 h-4" aria-hidden="true" /> | |
| )} | |
| </button> | |
| </div> | |
| </div> | |
| {/* Horizontal Studio Tabs */} | |
| <div className="hidden md:block border-t border-[#e7e5e0] bg-[#fafaf8]/90"> | |
| <nav | |
| aria-label="Điều hướng Studio" | |
| className="max-w-7xl mx-auto px-4 sm:px-8 flex items-center gap-1 overflow-x-auto" | |
| > | |
| {visibleTabs.map((tab) => { | |
| const Icon = tab.icon; | |
| const active = pathname === tab.href; | |
| return ( | |
| <Link | |
| key={tab.href} | |
| href={tab.href} | |
| aria-current={active ? "page" : undefined} | |
| className={`inline-flex items-center gap-2 px-4 py-3 text-xs font-semibold border-b-2 transition whitespace-nowrap ${ | |
| active | |
| ? "border-[#c2410c] text-[#111318]" | |
| : "border-transparent text-slate-600 hover:text-[#111318]" | |
| }`} | |
| > | |
| <Icon | |
| className={`w-3.5 h-3.5 ${active ? "text-[#c2410c]" : "text-slate-400"}`} | |
| aria-hidden="true" | |
| /> | |
| <span>{tab.label}</span> | |
| </Link> | |
| ); | |
| })} | |
| </nav> | |
| </div> | |
| {mobileMenu && ( | |
| <nav | |
| aria-label="Điều hướng di động" | |
| className="md:hidden border-t border-[#e7e5e0] bg-white px-4 py-3 space-y-1" | |
| > | |
| {visibleTabs.map((tab) => { | |
| const Icon = tab.icon; | |
| const active = pathname === tab.href; | |
| return ( | |
| <Link | |
| key={tab.href} | |
| href={tab.href} | |
| onClick={() => setMobileMenu(false)} | |
| className={`flex items-center gap-2.5 px-3 py-2.5 rounded-xl text-xs font-semibold ${ | |
| active | |
| ? "bg-orange-50 text-[#c2410c]" | |
| : "text-slate-700 hover:bg-[#fafaf8]" | |
| }`} | |
| > | |
| <Icon className="w-4 h-4" aria-hidden="true" /> | |
| <span>{tab.label}</span> | |
| </Link> | |
| ); | |
| })} | |
| <button | |
| type="button" | |
| onClick={handleSignOut} | |
| className="w-full flex items-center gap-2.5 px-3 py-2.5 rounded-xl text-xs font-semibold text-rose-700 hover:bg-rose-50" | |
| > | |
| <LogOut className="w-4 h-4" aria-hidden="true" /> | |
| <span>Đăng xuất</span> | |
| </button> | |
| </nav> | |
| )} | |
| </header> | |
| <main id="main-content" className="flex-1 flex flex-col"> | |
| {children} | |
| </main> | |
| </div> | |
| ); | |
| } | |