add back ModeType to TopControls

This commit is contained in:
EthanHealy01 2025-08-22 14:55:41 +01:00
parent 9f929ae335
commit 1708a9b13b

View File

@ -5,9 +5,10 @@ import rainbowStyles from '../../styles/rainbow.module.css';
import VisibilityIcon from "@mui/icons-material/Visibility"; import VisibilityIcon from "@mui/icons-material/Visibility";
import EditNoteIcon from "@mui/icons-material/EditNote"; import EditNoteIcon from "@mui/icons-material/EditNote";
import FolderIcon from "@mui/icons-material/Folder"; import FolderIcon from "@mui/icons-material/Folder";
import { ModeType, isValidMode } from '../../contexts/NavigationContext';
// Create view options with icons and loading states // Create view options with icons and loading states
const createViewOptions = (switchingTo: string | null) => [ const createViewOptions = (switchingTo: ModeType | null) => [
{ {
label: ( label: (
<div style={{ display: 'inline-flex', flexDirection: 'row', alignItems: 'center', gap: 6, whiteSpace: 'nowrap'}}> <div style={{ display: 'inline-flex', flexDirection: 'row', alignItems: 'center', gap: 6, whiteSpace: 'nowrap'}}>
@ -50,8 +51,8 @@ const createViewOptions = (switchingTo: string | null) => [
]; ];
interface TopControlsProps { interface TopControlsProps {
currentView: string; currentView: ModeType;
setCurrentView: (view: string) => void; setCurrentView: (view: ModeType) => void;
selectedToolKey?: string | null; selectedToolKey?: string | null;
} }
@ -61,19 +62,25 @@ const TopControls = ({
selectedToolKey, selectedToolKey,
}: TopControlsProps) => { }: TopControlsProps) => {
const { isRainbowMode } = useRainbowThemeContext(); const { isRainbowMode } = useRainbowThemeContext();
const [switchingTo, setSwitchingTo] = useState<string | null>(null); const [switchingTo, setSwitchingTo] = useState<ModeType | null>(null);
const isToolSelected = selectedToolKey !== null; const isToolSelected = selectedToolKey !== null;
const handleViewChange = useCallback((view: string) => { const handleViewChange = useCallback((view: string) => {
if (!isValidMode(view)) {
// Ignore invalid values defensively
return;
}
const mode = view as ModeType;
// Show immediate feedback // Show immediate feedback
setSwitchingTo(view); setSwitchingTo(mode);
// Defer the heavy view change to next frame so spinner can render // Defer the heavy view change to next frame so spinner can render
requestAnimationFrame(() => { requestAnimationFrame(() => {
// Give the spinner one more frame to show // Give the spinner one more frame to show
requestAnimationFrame(() => { requestAnimationFrame(() => {
setCurrentView(view); setCurrentView(mode);
// Clear the loading state after view change completes // Clear the loading state after view change completes
setTimeout(() => setSwitchingTo(null), 300); setTimeout(() => setSwitchingTo(null), 300);