import React, { useEffect, useRef, useState } from "react"; import { NavLink, Outlet, useLocation , useNavigate } from "react-router"; import { LuSettings, LuMouse, LuKeyboard, LuVideo, LuCpu, LuShieldCheck, LuWrench, LuArrowLeft, LuPalette, LuCommand, LuNetwork, LuUsers, } from "react-icons/lu"; import { useResizeObserver } from "usehooks-ts"; import { cx } from "@/cva.config"; import Card from "@components/Card"; import { LinkButton } from "@components/Button"; import { FeatureFlag } from "@components/FeatureFlag"; import { useUiStore } from "@/hooks/stores"; import { useSessionStore } from "@/stores/sessionStore"; import { usePermissions } from "@/hooks/usePermissions"; import { Permission } from "@/types/permissions"; /* TODO: Migrate to using URLs instead of the global state. To simplify the refactoring, we'll keep the global state for now. */ export default function SettingsRoute() { const location = useLocation(); const navigate = useNavigate(); const { setDisableVideoFocusTrap } = useUiStore(); const { currentMode } = useSessionStore(); const { hasPermission, isLoading, permissions } = usePermissions(); useEffect(() => { if (!isLoading && !permissions[Permission.SETTINGS_ACCESS] && currentMode !== null) { navigate("/", { replace: true }); } }, [permissions, isLoading, currentMode, navigate]); const scrollContainerRef = useRef(null); const [showLeftGradient, setShowLeftGradient] = useState(false); const [showRightGradient, setShowRightGradient] = useState(false); const { width = 0 } = useResizeObserver({ ref: scrollContainerRef as React.RefObject }); // Handle scroll position to show/hide gradients const handleScroll = () => { if (scrollContainerRef.current) { const { scrollLeft, scrollWidth, clientWidth } = scrollContainerRef.current; // Show left gradient only if scrolled to the right setShowLeftGradient(scrollLeft > 0); // Show right gradient only if there's more content to scroll to the right setShowRightGradient(scrollLeft < scrollWidth - clientWidth - 1); // -1 for rounding errors } }; useEffect(() => { // Check initial scroll position handleScroll(); // Add scroll event listener to the container const scrollContainer = scrollContainerRef.current; if (scrollContainer) { scrollContainer.addEventListener("scroll", handleScroll); } return () => { // Clean up event listener if (scrollContainer) { scrollContainer.removeEventListener("scroll", handleScroll); } }; }, [width]); useEffect(() => { setTimeout(() => { setDisableVideoFocusTrap(true); }, 500); return () => { setDisableVideoFocusTrap(false); }; }, [setDisableVideoFocusTrap]); // Check permissions first - return early to prevent any content flash // Show loading state while permissions are being checked if (isLoading) { return (
Checking permissions...
); } // Don't render settings content if user doesn't have permission if (!hasPermission(Permission.SETTINGS_ACCESS)) { return null; } return (
{/* Gradient overlay for left side - only visible on mobile when scrolled */}
{/* Gradient overlay for right side - only visible on mobile when there's more content */}
(isActive ? "active" : "")} >

General

(isActive ? "active" : "")} >

Mouse

(isActive ? "active" : "")} >

Keyboard

(isActive ? "active" : "")} >

Video

(isActive ? "active" : "")} >

Hardware

(isActive ? "active" : "")} >

Access

(isActive ? "active" : "")} >

Appearance

(isActive ? "active" : "")} >

Keyboard Macros

(isActive ? "active" : "")} >

Network

(isActive ? "active" : "")} >

Multi-Session Access

(isActive ? "active" : "")} >

Advanced

{/* */}
{/*
*/}
); }