Fix ViewType usage

This commit is contained in:
James Brunton 2025-08-18 14:19:17 +01:00
parent acbebd67a3
commit 3c131bc332
3 changed files with 19 additions and 8 deletions

View File

@ -142,7 +142,7 @@ export default function Workbench() {
{/* Top Controls */} {/* Top Controls */}
<TopControls <TopControls
currentView={currentView} currentView={currentView}
setCurrentView={setCurrentView as any /* FIX ME */} setCurrentView={setCurrentView}
selectedToolKey={selectedToolKey} selectedToolKey={selectedToolKey}
/> />

View File

@ -10,6 +10,7 @@ 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 { Group } from "@mantine/core"; import { Group } from "@mantine/core";
import { isViewType, ViewType } from "../../types/fileContext";
// This will be created inside the component to access switchingTo // This will be created inside the component to access switchingTo
const createViewOptions = (switchingTo: string | null) => [ const createViewOptions = (switchingTo: string | null) => [
@ -52,8 +53,8 @@ const createViewOptions = (switchingTo: string | null) => [
]; ];
interface TopControlsProps { interface TopControlsProps {
currentView: string; currentView: ViewType;
setCurrentView: (view: string) => void; setCurrentView: (view: ViewType) => void;
selectedToolKey?: string | null; selectedToolKey?: string | null;
} }
@ -67,7 +68,7 @@ const TopControls = ({
const isToolSelected = selectedToolKey !== null; const isToolSelected = selectedToolKey !== null;
const handleViewChange = useCallback((view: string) => { const handleViewChange = useCallback((view: ViewType) => {
// Show immediate feedback // Show immediate feedback
setSwitchingTo(view); setSwitchingTo(view);
@ -119,7 +120,7 @@ const TopControls = ({
<SegmentedControl <SegmentedControl
data={createViewOptions(switchingTo)} data={createViewOptions(switchingTo)}
value={currentView} value={currentView}
onChange={handleViewChange} onChange={(value) => isViewType(value) && handleViewChange}
color="blue" color="blue"
radius="xl" radius="xl"
size="md" size="md"

View File

@ -19,7 +19,17 @@ export type ModeType =
| 'changePermissions' | 'changePermissions'
| 'removePassword'; | 'removePassword';
export type ViewType = 'viewer' | 'pageEditor' | 'fileEditor'; const VIEW_TYPES = [
'viewer',
'pageEditor',
'fileEditor',
] as const;
export type ViewType = typeof VIEW_TYPES[number];
export const isViewType = (value: string): value is ViewType => {
return VIEW_TYPES.includes(value as ViewType);
}
export type ToolType = 'merge' | 'split' | 'compress' | 'ocr' | 'convert' | 'sanitize'; export type ToolType = 'merge' | 'split' | 'compress' | 'ocr' | 'convert' | 'sanitize';