diff --git a/src/app/client/client-view.tsx b/src/app/client/client-view.tsx index d6f2500e..99868409 100644 --- a/src/app/client/client-view.tsx +++ b/src/app/client/client-view.tsx @@ -1,6 +1,6 @@ "use client"; -import { ChevronLeft, ChevronRight, LogOut } from "lucide-react"; +import { LogOut } from "lucide-react"; import Link from "next/link"; import { signOut } from "next-auth/react"; import { @@ -9,7 +9,6 @@ import { useEffect, useState, } from "react"; -import { createPortal } from "react-dom"; function ToolbarBtn({ onClick, @@ -99,147 +98,170 @@ export function ClientView({ const sep = base.includes("?") ? "&" : "?"; const clientSrc = `${base}${sep}sso=${encodeURIComponent(ticket)}`; - const [mounted, setMounted] = useState(false); - const [position, setPosition] = useState<"left" | "right">("right"); + const POSITIONS = ["top-left", "top-right", "bottom-right", "bottom-left"] as const; + type Position = (typeof POSITIONS)[number]; - useEffect(() => { setMounted(true); }, []); + const [position, setPosition] = useState("top-right"); useEffect(() => { const params = new URLSearchParams(window.location.search); const urlPos = params.get("toolbar"); - if (urlPos === "left" || urlPos === "right") { - setPosition(urlPos); + if ((POSITIONS as readonly string[]).includes(urlPos ?? "")) { + setPosition(urlPos as Position); return; } try { const stored = localStorage.getItem("client_toolbar_position"); - if (stored === "left" || stored === "right") { - setPosition(stored); + if ((POSITIONS as readonly string[]).includes(stored ?? "")) { + setPosition(stored as Position); return; } } catch { /* private mode */ } - if (defaultToolbarPosition === "left" || defaultToolbarPosition === "right") - setPosition(defaultToolbarPosition as "left" | "right"); + if ((POSITIONS as readonly string[]).includes(defaultToolbarPosition)) + setPosition(defaultToolbarPosition as Position); }, [defaultToolbarPosition]); - function togglePosition() { - const next = position === "left" ? "right" : "left"; + function cyclePosition() { + const idx = POSITIONS.indexOf(position); + const next = POSITIONS[(idx + 1) % POSITIONS.length]; setPosition(next); try { localStorage.setItem("client_toolbar_position", next); } catch {} } - const toolbar = ( -
- - - Home - - - - - window.location.reload()} title="Reload"> - - Reload - - - - - - - - Fullscreen - - - -
- - Online users - - - - {onlineCount} -
- - {position === "left" ? : } - - signOut({ callbackUrl: "/" })} - title="Logout" - > - - -
- ); + const posStyle: React.CSSProperties = {}; + if (position === "top-left") { posStyle.top = posStyle.left = "0.5rem"; } + else if (position === "top-right") { posStyle.top = posStyle.right = "0.5rem"; } + else if (position === "bottom-right") { posStyle.bottom = posStyle.right = "0.5rem"; } + else if (position === "bottom-left") { posStyle.bottom = posStyle.left = "0.5rem"; } return ( -
- {mounted && createPortal(toolbar, document.body)} + <> +
+ + + Home + + + + + window.location.reload()} title="Reload"> + + Reload + + + + + + + + Fullscreen + + + +
+ + Online users + + + + {onlineCount} +
+ + + Move toolbar + + + + + signOut({ callbackUrl: "/" })} + title="Logout" + > + + +
-