diff --git a/frontend/src/contexts/ToolWorkflowContext.tsx b/frontend/src/contexts/ToolWorkflowContext.tsx index 7ace72336..7a5652c63 100644 --- a/frontend/src/contexts/ToolWorkflowContext.tsx +++ b/frontend/src/contexts/ToolWorkflowContext.tsx @@ -7,7 +7,7 @@ import React, { createContext, useContext, useReducer, useCallback, useMemo, use import { useToolManagement } from '../hooks/useToolManagement'; import { PageEditorFunctions } from '../types/pageEditor'; import { ToolRegistryEntry, ToolRegistry } from '../data/toolsTaxonomy'; -import { useNavigationActions, useNavigationState } from './NavigationContext'; +import { useNavigationActions, useNavigationState } from '../contexts/NavigationContext'; import { ToolId, isValidToolId } from '../types/toolId'; import { WorkbenchType, getDefaultWorkbench, isBaseWorkbench } from '../types/workbench'; import { useNavigationUrlSync } from '../hooks/useUrlSync'; @@ -17,10 +17,10 @@ import { ToolWorkflowState, createInitialState, toolWorkflowReducer, -} from './toolWorkflow/toolWorkflowState'; +} from '../contexts/toolWorkflow/toolWorkflowState'; import type { ToolPanelMode } from '../constants/toolPanel'; -import { usePreferences } from './PreferencesContext'; -import { useToolRegistry } from './ToolRegistryContext'; +import { usePreferences } from '../contexts/PreferencesContext'; +import { useToolRegistry } from '../contexts/ToolRegistryContext'; // State interface // Types and reducer/state moved to './toolWorkflow/state' @@ -31,11 +31,11 @@ export interface CustomWorkbenchViewRegistration { workbenchId: WorkbenchType; label: string; icon?: React.ReactNode; - component: React.ComponentType<{ data: unknown }>; + component: React.ComponentType<{ data: any }>; } export interface CustomWorkbenchViewInstance extends CustomWorkbenchViewRegistration { - data: unknown | null; + data: any; } interface ToolWorkflowContextValue extends ToolWorkflowState { @@ -80,21 +80,16 @@ interface ToolWorkflowContextValue extends ToolWorkflowState { customWorkbenchViews: CustomWorkbenchViewInstance[]; registerCustomWorkbenchView: (view: CustomWorkbenchViewRegistration) => void; unregisterCustomWorkbenchView: (id: string) => void; - setCustomWorkbenchViewData: (id: string, data: unknown) => void; + setCustomWorkbenchViewData: (id: string, data: any) => void; clearCustomWorkbenchViewData: (id: string) => void; } // Ensure a single context instance across HMR to avoid provider/consumer mismatches const __GLOBAL_CONTEXT_KEY__ = '__ToolWorkflowContext__'; -type ToolWorkflowGlobalThis = typeof globalThis & { - [__GLOBAL_CONTEXT_KEY__]?: React.Context; -}; - -const toolWorkflowGlobal = globalThis as ToolWorkflowGlobalThis; -const existingContext = toolWorkflowGlobal[__GLOBAL_CONTEXT_KEY__]; +const existingContext = (globalThis as any)[__GLOBAL_CONTEXT_KEY__] as React.Context | undefined; const ToolWorkflowContext = existingContext ?? createContext(undefined); if (!existingContext) { - toolWorkflowGlobal[__GLOBAL_CONTEXT_KEY__] = ToolWorkflowContext; + (globalThis as any)[__GLOBAL_CONTEXT_KEY__] = ToolWorkflowContext; } // Provider component @@ -110,7 +105,7 @@ export function ToolWorkflowProvider({ children }: ToolWorkflowProviderProps) { const [toolResetFunctions, setToolResetFunctions] = React.useState void>>({}); const [customViewRegistry, setCustomViewRegistry] = React.useState>({}); - const [customViewData, setCustomViewData] = React.useState>({}); + const [customViewData, setCustomViewData] = React.useState>({}); // Navigation actions and state are available since we're inside NavigationProvider const { actions } = useNavigationActions(); @@ -200,7 +195,7 @@ export function ToolWorkflowProvider({ children }: ToolWorkflowProviderProps) { } }, [actions, navigationState.workbench]); - const setCustomWorkbenchViewData = useCallback((id: string, data: unknown) => { + const setCustomWorkbenchViewData = useCallback((id: string, data: any) => { setCustomViewData(prev => ({ ...prev, [id]: data })); }, []); @@ -226,10 +221,10 @@ export function ToolWorkflowProvider({ children }: ToolWorkflowProviderProps) { if (isBaseWorkbench(navigationState.workbench)) { return; } - // Keep guard lightweight; remove verbose logging + const currentCustomView = customWorkbenchViews.find(view => view.workbenchId === navigationState.workbench); if (!currentCustomView || currentCustomView.data == null) { - return; + actions.setWorkbench(getDefaultWorkbench()); } }, [actions, customWorkbenchViews, navigationState.workbench]); @@ -426,4 +421,4 @@ export function useToolWorkflow(): ToolWorkflowContextValue { throw new Error('useToolWorkflow must be used within a ToolWorkflowProvider'); } return context; -} +} \ No newline at end of file diff --git a/frontend/src/hooks/useFileHandler.ts b/frontend/src/hooks/useFileHandler.ts index 2ce0fe3dc..c29b5bd36 100644 --- a/frontend/src/hooks/useFileHandler.ts +++ b/frontend/src/hooks/useFileHandler.ts @@ -8,7 +8,7 @@ export const useFileHandler = () => { // Merge default options with passed options - passed options take precedence const mergedOptions = { selectFiles: true, ...options }; // Let FileContext handle deduplication with quickKey logic - return await actions.addFiles(files, mergedOptions); + await actions.addFiles(files, mergedOptions); }, [actions.addFiles]); return { diff --git a/frontend/src/tools/ValidateSignature.tsx b/frontend/src/tools/ValidateSignature.tsx index 30a3a786d..45a6bdac6 100644 --- a/frontend/src/tools/ValidateSignature.tsx +++ b/frontend/src/tools/ValidateSignature.tsx @@ -39,10 +39,7 @@ const ValidateSignature = (props: BaseToolProps) => { const hasResults = operation.results.length > 0; const showResultsStep = hasResults || base.operation.isLoading || !!base.operation.errorMessage; - // Adapter to satisfy ComponentType<{ data: unknown }> - const ReportAdapter: React.ComponentType<{ data: unknown }> = ({ data }) => ( - - ); + useEffect(() => { registerCustomWorkbenchView({ @@ -50,7 +47,7 @@ const ValidateSignature = (props: BaseToolProps) => { workbenchId: REPORT_WORKBENCH_ID, label: t('validateSignature.report.shortTitle', 'Signature Report'), icon: reportIcon, - component: ReportAdapter, + component: ValidateSignatureReportView as any, }); return () => {