2025-04-17 15:12:28 +02:00
|
|
|
"use client"
|
2025-04-17 02:43:14 +02:00
|
|
|
|
2025-09-29 11:01:14 +02:00
|
|
|
import { Github, PlusCircle, Search } from "lucide-react"
|
|
|
|
|
import Link from "next/link"
|
|
|
|
|
import { useEffect, useState } from "react"
|
2025-04-17 15:12:28 +02:00
|
|
|
import { IconSubmissionForm } from "@/components/icon-submission-form"
|
|
|
|
|
import { ThemeSwitcher } from "@/components/theme-switcher"
|
|
|
|
|
import { REPO_PATH } from "@/constants"
|
2025-04-26 13:07:02 +02:00
|
|
|
import { getIconsArray } from "@/lib/api"
|
2025-10-01 15:47:02 +02:00
|
|
|
import { pb } from "@/lib/pb"
|
2025-04-26 13:07:02 +02:00
|
|
|
import type { IconWithName } from "@/types/icons"
|
|
|
|
|
import { CommandMenu } from "./command-menu"
|
2025-04-17 15:12:28 +02:00
|
|
|
import { HeaderNav } from "./header-nav"
|
|
|
|
|
import { Button } from "./ui/button"
|
|
|
|
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./ui/tooltip"
|
2025-10-01 15:47:02 +02:00
|
|
|
import { LoginPopup } from "./user-button"
|
|
|
|
|
|
|
|
|
|
interface UserData {
|
|
|
|
|
username: string
|
|
|
|
|
email: string
|
|
|
|
|
avatar?: string
|
|
|
|
|
}
|
2025-04-17 02:43:14 +02:00
|
|
|
|
|
|
|
|
export function Header() {
|
2025-04-26 13:07:02 +02:00
|
|
|
const [iconsData, setIconsData] = useState<IconWithName[]>([])
|
|
|
|
|
const [isLoaded, setIsLoaded] = useState(false)
|
|
|
|
|
const [commandMenuOpen, setCommandMenuOpen] = useState(false)
|
2025-10-01 15:47:02 +02:00
|
|
|
const [isLoggedIn, setIsLoggedIn] = useState(false)
|
|
|
|
|
const [userData, setUserData] = useState<UserData | undefined>(undefined)
|
2025-04-26 13:07:02 +02:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
async function loadIcons() {
|
|
|
|
|
try {
|
|
|
|
|
const icons = await getIconsArray()
|
|
|
|
|
setIconsData(icons)
|
|
|
|
|
setIsLoaded(true)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Failed to load icons:", error)
|
|
|
|
|
setIsLoaded(true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadIcons()
|
|
|
|
|
}, [])
|
|
|
|
|
|
2025-10-01 15:47:02 +02:00
|
|
|
useEffect(() => {
|
|
|
|
|
// Initialize auth state from PocketBase authStore
|
|
|
|
|
const updateAuthState = () => {
|
|
|
|
|
if (pb.authStore.isValid && pb.authStore.record) {
|
|
|
|
|
setIsLoggedIn(true)
|
|
|
|
|
setUserData({
|
|
|
|
|
username: pb.authStore.record.username || pb.authStore.record.email,
|
|
|
|
|
email: pb.authStore.record.email,
|
|
|
|
|
avatar: pb.authStore.record.avatar
|
|
|
|
|
? `${pb.baseURL}/api/files/_pb_users_auth_/${pb.authStore.record.id}/${pb.authStore.record.avatar}`
|
|
|
|
|
: undefined,
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
setIsLoggedIn(false)
|
|
|
|
|
setUserData(undefined)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set initial state
|
|
|
|
|
updateAuthState()
|
|
|
|
|
|
|
|
|
|
// Listen for auth changes
|
|
|
|
|
const unsubscribe = pb.authStore.onChange(() => {
|
|
|
|
|
updateAuthState()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Cleanup listener on unmount
|
|
|
|
|
return () => {
|
|
|
|
|
unsubscribe()
|
|
|
|
|
}
|
|
|
|
|
}, [])
|
|
|
|
|
|
2025-04-26 13:07:02 +02:00
|
|
|
// Function to open the command menu
|
|
|
|
|
const openCommandMenu = () => {
|
|
|
|
|
setCommandMenuOpen(true)
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 15:47:02 +02:00
|
|
|
// Handle sign out using PocketBase
|
|
|
|
|
const handleSignOut = () => {
|
|
|
|
|
pb.authStore.clear()
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-16 16:18:20 +02:00
|
|
|
return (
|
2025-04-26 17:28:24 +02:00
|
|
|
<header className="border-b sticky top-0 z-50 backdrop-blur-2xl bg-background/50 border-border/50">
|
2025-04-17 02:43:14 +02:00
|
|
|
<div className="px-4 md:px-12 flex items-center justify-between h-16 md:h-18">
|
2025-04-16 16:18:20 +02:00
|
|
|
<div className="flex items-center gap-2 md:gap-6">
|
2025-10-01 15:47:02 +02:00
|
|
|
<Link
|
|
|
|
|
href="/"
|
|
|
|
|
className="text-lg md:text-xl font-bold group hidden md:block"
|
|
|
|
|
>
|
|
|
|
|
<span className="transition-colors duration-300 group-hover:">
|
|
|
|
|
Dashboard Icons
|
|
|
|
|
</span>
|
2025-04-16 16:18:20 +02:00
|
|
|
</Link>
|
2025-04-17 10:29:05 +02:00
|
|
|
<div className="flex-nowrap">
|
2025-04-17 02:43:14 +02:00
|
|
|
<HeaderNav />
|
|
|
|
|
</div>
|
2025-04-16 16:18:20 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-2 md:gap-4">
|
2025-04-26 13:07:02 +02:00
|
|
|
{/* Desktop search button */}
|
|
|
|
|
<div className="hidden md:block">
|
2025-10-01 15:47:02 +02:00
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
className="gap-2 cursor-pointer transition-all duration-300"
|
|
|
|
|
onClick={openCommandMenu}
|
|
|
|
|
>
|
2025-04-26 13:07:02 +02:00
|
|
|
<Search className="h-4 w-4 transition-all duration-300" />
|
|
|
|
|
<span>Find icons</span>
|
|
|
|
|
<kbd className="pointer-events-none inline-flex h-5 select-none items-center gap-1 rounded border border-border/80 bg-muted/80 px-1.5 font-mono text-[10px] font-medium opacity-100">
|
|
|
|
|
<span className="text-xs">⌘</span>K
|
|
|
|
|
</kbd>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Mobile search button */}
|
|
|
|
|
<div className="md:hidden">
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="rounded-lg cursor-pointer transition-all duration-300 hover:ring-2 "
|
|
|
|
|
onClick={openCommandMenu}
|
|
|
|
|
>
|
|
|
|
|
<Search className="h-5 w-5 transition-all duration-300" />
|
|
|
|
|
<span className="sr-only">Find icons</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-04-26 22:56:39 +02:00
|
|
|
{/* Mobile Submit Button -> triggers IconSubmissionForm dialog */}
|
|
|
|
|
<div className="md:hidden">
|
|
|
|
|
<IconSubmissionForm
|
|
|
|
|
trigger={
|
2025-10-01 15:47:02 +02:00
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="rounded-lg cursor-pointer transition-all duration-300 hover:ring-2 "
|
|
|
|
|
>
|
2025-04-26 22:56:39 +02:00
|
|
|
<PlusCircle className="h-5 w-5 transition-all duration-300" />
|
|
|
|
|
<span className="sr-only">Submit icon(s)</span>
|
|
|
|
|
</Button>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-04-17 02:43:14 +02:00
|
|
|
<div className="hidden md:flex items-center gap-2 md:gap-4">
|
2025-04-26 22:56:39 +02:00
|
|
|
{/* Desktop Submit Button */}
|
2025-04-17 02:43:14 +02:00
|
|
|
<IconSubmissionForm />
|
|
|
|
|
<TooltipProvider>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
2025-04-18 16:51:04 +02:00
|
|
|
className="rounded-lg cursor-pointer transition-all duration-300 hover:ring-2"
|
2025-04-17 02:43:14 +02:00
|
|
|
asChild
|
|
|
|
|
>
|
|
|
|
|
<Link href={REPO_PATH} target="_blank" className="group">
|
2025-04-17 15:11:17 +02:00
|
|
|
<Github className="h-5 w-5 group-hover: transition-all duration-300" />
|
2025-04-17 07:21:19 +02:00
|
|
|
<span className="sr-only">View on GitHub</span>
|
2025-04-17 02:43:14 +02:00
|
|
|
</Link>
|
|
|
|
|
</Button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
2025-04-17 07:21:19 +02:00
|
|
|
<p>View on GitHub</p>
|
2025-04-17 02:43:14 +02:00
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
|
|
|
|
</div>
|
2025-04-16 16:18:20 +02:00
|
|
|
<ThemeSwitcher />
|
2025-10-01 15:47:02 +02:00
|
|
|
<LoginPopup
|
|
|
|
|
isLoggedIn={isLoggedIn}
|
|
|
|
|
userData={isLoggedIn ? userData : undefined}
|
|
|
|
|
onSignOut={handleSignOut}
|
|
|
|
|
/>
|
2025-04-16 16:18:20 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-04-26 13:07:02 +02:00
|
|
|
|
|
|
|
|
{/* Single instance of CommandMenu */}
|
2025-10-01 15:47:02 +02:00
|
|
|
{isLoaded && (
|
|
|
|
|
<CommandMenu
|
|
|
|
|
icons={iconsData}
|
|
|
|
|
open={commandMenuOpen}
|
|
|
|
|
onOpenChange={setCommandMenuOpen}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2025-04-26 13:07:02 +02:00
|
|
|
</header>
|
2025-10-01 15:47:02 +02:00
|
|
|
);
|
2025-04-26 17:28:24 +02:00
|
|
|
}
|