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 */}
<TopControls
currentView={currentView}
setCurrentView={setCurrentView as any /* FIX ME */}
setCurrentView={setCurrentView}
selectedToolKey={selectedToolKey}
/>

View File

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

View File

@ -19,7 +19,17 @@ export type ModeType =
| 'changePermissions'
| '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';
@ -108,12 +118,12 @@ export interface FileContextActions {
removeFiles: (fileIds: string[], deleteFromStorage?: boolean) => void;
replaceFile: (oldFileId: string, newFile: File) => Promise<void>;
clearAllFiles: () => void;
// File pinning
pinFile: (file: File) => void;
unpinFile: (file: File) => void;
isFilePinned: (file: File) => boolean;
// File consumption (replace unpinned files with outputs)
consumeFiles: (inputFiles: File[], outputFiles: File[]) => Promise<void>;