import { ModeToggle } from "@/components/ThemeSwitcher" import { Separator } from "@/components/ui/separator" import { Skeleton } from "@/components/ui/skeleton" import { useBackground } from "@/hooks/use-background" import { useWebSocketContext } from "@/hooks/use-websocket-context" import { fetchLoginUser, fetchSetting } from "@/lib/nezha-api" import { cn } from "@/lib/utils" import { useQuery } from "@tanstack/react-query" import { AnimatePresence, m } from "framer-motion" import { ImageMinus } from "lucide-react" import { DateTime } from "luxon" import { useEffect, useRef, useState } from "react" import { useTranslation } from "react-i18next" import { useNavigate } from "react-router-dom" import { LanguageSwitcher } from "./LanguageSwitcher" import { Loader, LoadingSpinner } from "./loading/Loader" import { Button } from "./ui/button" function Header() { const { t } = useTranslation() const navigate = useNavigate() const { backgroundImage, updateBackground } = useBackground() const { data: settingData, isLoading } = useQuery({ queryKey: ["setting"], queryFn: () => fetchSetting(), refetchOnMount: true, refetchOnWindowFocus: true, }) const { lastMessage, connected } = useWebSocketContext() const onlineCount = connected ? (lastMessage ? JSON.parse(lastMessage.data).online || 0 : 0) : "..." const siteName = settingData?.data?.config?.site_name // @ts-expect-error CustomLogo is a global variable const customLogo = window.CustomLogo || "/apple-touch-icon.png" // @ts-expect-error CustomDesc is a global variable const customDesc = window.CustomDesc || t("nezha") useEffect(() => { const link = document.querySelector("link[rel*='icon']") || document.createElement("link") // @ts-expect-error set link.type link.type = "image/x-icon" // @ts-expect-error set link.rel link.rel = "shortcut icon" // @ts-expect-error set link.href link.href = customLogo document.getElementsByTagName("head")[0].appendChild(link) }, [customLogo]) useEffect(() => { document.title = siteName || "CZL SVR" }, [siteName]) const handleBackgroundToggle = () => { if (window.CustomBackgroundImage) { // Store the current background image before removing it sessionStorage.setItem("savedBackgroundImage", window.CustomBackgroundImage) updateBackground(undefined) } else { // Restore the saved background image const savedImage = sessionStorage.getItem("savedBackgroundImage") if (savedImage) { updateBackground(savedImage) } } } const customBackgroundImage = backgroundImage return (
{customDesc}
{t("refreshing")}...
👋 {t("overview")}
{t("whereTheTimeIs")}
{mouted ? ({timeString}
) : (