import React, { useState, useCallback } from "react"; import { SegmentedControl, Loader } from "@mantine/core"; import { useRainbowThemeContext } from "./RainbowThemeProvider"; import rainbowStyles from '../../styles/rainbow.module.css'; import VisibilityIcon from "@mui/icons-material/Visibility"; import EditNoteIcon from "@mui/icons-material/EditNote"; import FolderIcon from "@mui/icons-material/Folder"; // Create view options with icons and loading states const createViewOptions = (switchingTo: string | null) => [ { label: (
{switchingTo === "viewer" ? ( ) : ( )} Read
), value: "viewer", }, { label: (
{switchingTo === "pageEditor" ? ( ) : ( )} Page Editor
), value: "pageEditor", }, { label: (
{switchingTo === "fileEditor" ? ( ) : ( )} File Manager
), value: "fileEditor", }, ]; interface TopControlsProps { currentView: string; setCurrentView: (view: string) => void; selectedToolKey?: string | null; } const TopControls = ({ currentView, setCurrentView, selectedToolKey, }: TopControlsProps) => { const { isRainbowMode } = useRainbowThemeContext(); const [switchingTo, setSwitchingTo] = useState(null); const isToolSelected = selectedToolKey !== null; const handleViewChange = useCallback((view: string) => { // Show immediate feedback setSwitchingTo(view); // Defer the heavy view change to next frame so spinner can render requestAnimationFrame(() => { // Give the spinner one more frame to show requestAnimationFrame(() => { setCurrentView(view); // Clear the loading state after view change completes setTimeout(() => setSwitchingTo(null), 300); }); }); }, [setCurrentView]); return (
{!isToolSelected && (
)}
); }; export default TopControls;