diff --git a/frontend/src/components/tools/automate/AutomationRun.tsx b/frontend/src/components/tools/automate/AutomationRun.tsx index 555107cb8..33263dd1f 100644 --- a/frontend/src/components/tools/automate/AutomationRun.tsx +++ b/frontend/src/components/tools/automate/AutomationRun.tsx @@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next"; import { Button, Text, Stack, Group, Card, Progress } from "@mantine/core"; import PlayArrowIcon from "@mui/icons-material/PlayArrow"; import CheckIcon from "@mui/icons-material/Check"; -import { useFileSelection } from "../../../contexts/FileSelectionContext"; +import { useFileSelection } from "../../../contexts/FileContext"; import { useFlatToolRegistry } from "../../../data/useTranslatedToolRegistry"; interface AutomationRunProps { diff --git a/frontend/src/components/tools/shared/SuggestedToolsSection.tsx b/frontend/src/components/tools/shared/SuggestedToolsSection.tsx index 18e7a0fc2..d44b99667 100644 --- a/frontend/src/components/tools/shared/SuggestedToolsSection.tsx +++ b/frontend/src/components/tools/shared/SuggestedToolsSection.tsx @@ -1,15 +1,22 @@ -import React from 'react'; +import React, { useCallback } from 'react'; import { Stack, Text, Divider, Card, Group } from '@mantine/core'; import { useTranslation } from 'react-i18next'; import { useSuggestedTools } from '../../../hooks/useSuggestedTools'; -import { useToolNavigation } from '../../../contexts/ToolNavigationContext'; +import { useNavigationActions, useNavigationState, type ModeType } from '../../../contexts/NavigationContext'; export interface SuggestedToolsSectionProps {} export function SuggestedToolsSection(): React.ReactElement { const { t } = useTranslation(); - const { handleToolSelect, selectedToolKey } = useToolNavigation(); - const suggestedTools = useSuggestedTools(selectedToolKey, handleToolSelect); + const { actions } = useNavigationActions(); + const { currentMode } = useNavigationState(); + + // Create handleToolSelect function that navigates to the tool + const handleToolSelect = useCallback((toolId: string) => { + actions.setMode(toolId as ModeType); + }, [actions]); + + const suggestedTools = useSuggestedTools(currentMode, handleToolSelect); return ( diff --git a/frontend/src/contexts/ToolNavigationContext.tsx b/frontend/src/contexts/ToolNavigationContext.tsx index 1e82b6c6f..6a4fb4825 100644 --- a/frontend/src/contexts/ToolNavigationContext.tsx +++ b/frontend/src/contexts/ToolNavigationContext.tsx @@ -1,85 +1,85 @@ -/** - * ToolNavigationContext - Handles tool selection and navigation without tool registry - * This breaks the circular dependency by not importing the tool registry - */ +// /** +// * ToolNavigationContext - Handles tool selection and navigation without tool registry +// * This breaks the circular dependency by not importing the tool registry +// */ -import React, { createContext, useContext, useState, useCallback } from 'react'; -import { useFileContext } from './FileContext'; +// import React, { createContext, useContext, useState, useCallback } from 'react'; +// import { useFileContext } from './FileContext'; -// Navigation state interface -interface ToolNavigationState { - selectedToolKey: string | null; -} +// // Navigation state interface +// interface ToolNavigationState { +// selectedToolKey: string | null; +// } -// Context value interface -interface ToolNavigationContextValue extends ToolNavigationState { - // Navigation Actions - selectTool: (toolKey: string) => void; - clearToolSelection: () => void; - handleToolSelect: (toolId: string) => void; -} +// // Context value interface +// interface ToolNavigationContextValue extends ToolNavigationState { +// // Navigation Actions +// selectTool: (toolKey: string) => void; +// clearToolSelection: () => void; +// handleToolSelect: (toolId: string) => void; +// } -const ToolNavigationContext = createContext(undefined); +// const ToolNavigationContext = createContext(undefined); -// Provider component -interface ToolNavigationProviderProps { - children: React.ReactNode; -} +// // Provider component +// interface ToolNavigationProviderProps { +// children: React.ReactNode; +// } -export function ToolNavigationProvider({ children }: ToolNavigationProviderProps) { - const [selectedToolKey, setSelectedToolKey] = useState(null); - const { setCurrentView } = useFileContext(); +// export function ToolNavigationProvider({ children }: ToolNavigationProviderProps) { +// const [selectedToolKey, setSelectedToolKey] = useState(null); +// const { setCurrentView } = useFileContext(); - const selectTool = useCallback((toolKey: string) => { - setSelectedToolKey(toolKey); - }, []); +// const selectTool = useCallback((toolKey: string) => { +// setSelectedToolKey(toolKey); +// }, []); - const clearToolSelection = useCallback(() => { - setSelectedToolKey(null); - }, []); +// const clearToolSelection = useCallback(() => { +// setSelectedToolKey(null); +// }, []); - const handleToolSelect = useCallback((toolId: string) => { - // Handle special cases - if (toolId === 'allTools') { - clearToolSelection(); - return; - } +// const handleToolSelect = useCallback((toolId: string) => { +// // Handle special cases +// if (toolId === 'allTools') { +// clearToolSelection(); +// return; +// } - selectTool(toolId); - setCurrentView('fileEditor'); - }, [selectTool, setCurrentView, clearToolSelection]); +// selectTool(toolId); +// setCurrentView('fileEditor'); +// }, [selectTool, setCurrentView, clearToolSelection]); - const contextValue: ToolNavigationContextValue = { - selectedToolKey, - selectTool, - clearToolSelection, - handleToolSelect - }; +// const contextValue: ToolNavigationContextValue = { +// selectedToolKey, +// selectTool, +// clearToolSelection, +// handleToolSelect +// }; - return ( - - {children} - - ); -} +// return ( +// +// {children} +// +// ); +// } -// Custom hook to use the context -export function useToolNavigation(): ToolNavigationContextValue { - const context = useContext(ToolNavigationContext); - if (!context) { - // During development hot reload, temporarily return a safe fallback - if (process.env.NODE_ENV === 'development') { - console.warn('ToolNavigationContext temporarily unavailable during hot reload, using fallback'); - - return { - selectedToolKey: null, - selectTool: () => {}, - clearToolSelection: () => {}, - handleToolSelect: () => {} - } as ToolNavigationContextValue; - } - - throw new Error('useToolNavigation must be used within a ToolNavigationProvider'); - } - return context; -} \ No newline at end of file +// // Custom hook to use the context +// export function useToolNavigation(): ToolNavigationContextValue { +// const context = useContext(ToolNavigationContext); +// if (!context) { +// // During development hot reload, temporarily return a safe fallback +// if (process.env.NODE_ENV === 'development') { +// console.warn('ToolNavigationContext temporarily unavailable during hot reload, using fallback'); + +// return { +// selectedToolKey: null, +// selectTool: () => {}, +// clearToolSelection: () => {}, +// handleToolSelect: () => {} +// } as ToolNavigationContextValue; +// } + +// throw new Error('useToolNavigation must be used within a ToolNavigationProvider'); +// } +// return context; +// } diff --git a/frontend/src/hooks/tools/addPassword/useAddPasswordOperation.test.ts b/frontend/src/hooks/tools/addPassword/useAddPasswordOperation.test.ts index 747cd67b7..7e6032214 100644 --- a/frontend/src/hooks/tools/addPassword/useAddPasswordOperation.test.ts +++ b/frontend/src/hooks/tools/addPassword/useAddPasswordOperation.test.ts @@ -26,7 +26,7 @@ import { ToolOperationConfig, ToolOperationHook, useToolOperation } from '../sha describe('useAddPasswordOperation', () => { const mockUseToolOperation = vi.mocked(useToolOperation); - const getToolConfig = (): ToolOperationConfig => mockUseToolOperation.mock.calls[0][0]; + const getToolConfig = (): ToolOperationConfig => mockUseToolOperation.mock.calls[0][0] as ToolOperationConfig; const mockToolOperationReturn: ToolOperationHook = { files: [], diff --git a/frontend/src/hooks/tools/changePermissions/useChangePermissionsOperation.test.ts b/frontend/src/hooks/tools/changePermissions/useChangePermissionsOperation.test.ts index 845403841..715e44f73 100644 --- a/frontend/src/hooks/tools/changePermissions/useChangePermissionsOperation.test.ts +++ b/frontend/src/hooks/tools/changePermissions/useChangePermissionsOperation.test.ts @@ -25,7 +25,7 @@ import { ToolOperationConfig, ToolOperationHook, useToolOperation } from '../sha describe('useChangePermissionsOperation', () => { const mockUseToolOperation = vi.mocked(useToolOperation); - const getToolConfig = (): ToolOperationConfig => mockUseToolOperation.mock.calls[0][0]; + const getToolConfig = (): ToolOperationConfig => mockUseToolOperation.mock.calls[0][0] as ToolOperationConfig; const mockToolOperationReturn: ToolOperationHook = { files: [], diff --git a/frontend/src/hooks/tools/ocr/useOCROperation.ts b/frontend/src/hooks/tools/ocr/useOCROperation.ts index b6f06e31f..b816b3773 100644 --- a/frontend/src/hooks/tools/ocr/useOCROperation.ts +++ b/frontend/src/hooks/tools/ocr/useOCROperation.ts @@ -52,8 +52,8 @@ export const buildOCRFormData = (parameters: OCRParameters, file: File): FormDat return formData; }; -// Static response handler for OCR - can be used by automation executor -export const ocrResponseHandler = async (blob: Blob, originalFiles: File[], extractZipFiles: (blob: Blob) => Promise<{ success: boolean; extractedFiles: File[]; errors: string[] }>): Promise => { +// Static response handler for OCR - can be used by automation executor +export const ocrResponseHandler = async (blob: Blob, originalFiles: File[], extractZipFiles: (blob: Blob) => Promise): Promise => { const headBuf = await blob.slice(0, 8).arrayBuffer(); const head = new TextDecoder().decode(new Uint8Array(headBuf)); @@ -61,8 +61,8 @@ export const ocrResponseHandler = async (blob: Blob, originalFiles: File[], extr if (head.startsWith('PK')) { const base = stripExt(originalFiles[0].name); try { - const result = await extractZipFiles(blob); - if (result.success && result.extractedFiles.length > 0) return result.extractedFiles; + const extractedFiles = await extractZipFiles(blob); + if (extractedFiles.length > 0) return extractedFiles; } catch { /* ignore and try local extractor */ } try { const local = await extractZipFile(blob); // local fallback @@ -108,7 +108,9 @@ export const useOCROperation = () => { // OCR-specific parsing: ZIP (sidecar) vs PDF vs HTML error const responseHandler = useCallback(async (blob: Blob, originalFiles: File[]): Promise => { - return ocrResponseHandler(blob, originalFiles, extractZipFiles); + // extractZipFiles from useToolResources already returns File[] directly + const simpleExtractZipFiles = extractZipFiles; + return ocrResponseHandler(blob, originalFiles, simpleExtractZipFiles); }, [extractZipFiles]); const ocrConfig: ToolOperationConfig = { diff --git a/frontend/src/hooks/tools/removePassword/useRemovePasswordOperation.test.ts b/frontend/src/hooks/tools/removePassword/useRemovePasswordOperation.test.ts index 66cd240fc..61faef9a4 100644 --- a/frontend/src/hooks/tools/removePassword/useRemovePasswordOperation.test.ts +++ b/frontend/src/hooks/tools/removePassword/useRemovePasswordOperation.test.ts @@ -25,7 +25,7 @@ import { ToolOperationConfig, ToolOperationHook, useToolOperation } from '../sha describe('useRemovePasswordOperation', () => { const mockUseToolOperation = vi.mocked(useToolOperation); - const getToolConfig = (): ToolOperationConfig => mockUseToolOperation.mock.calls[0][0]; + const getToolConfig = (): ToolOperationConfig => mockUseToolOperation.mock.calls[0][0] as ToolOperationConfig; const mockToolOperationReturn: ToolOperationHook = { files: [], diff --git a/frontend/src/tools/Automate.tsx b/frontend/src/tools/Automate.tsx index 8983e0652..b3b72a50f 100644 --- a/frontend/src/tools/Automate.tsx +++ b/frontend/src/tools/Automate.tsx @@ -1,7 +1,7 @@ import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { useFileContext } from "../contexts/FileContext"; -import { useToolFileSelection } from "../contexts/FileSelectionContext"; +import { useFileSelection } from "../contexts/FileContext"; import { createToolFlow } from "../components/tools/shared/createToolFlow"; import { createFilesToolStep } from "../components/tools/shared/FilesToolStep"; @@ -16,8 +16,7 @@ import { useSavedAutomations } from "../hooks/tools/automate/useSavedAutomations const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => { const { t } = useTranslation(); - const { setCurrentMode } = useFileContext(); - const { selectedFiles } = useToolFileSelection(); + const { selectedFiles } = useFileSelection(); const [currentStep, setCurrentStep] = useState<'selection' | 'creation' | 'run'>('selection'); const [stepData, setStepData] = useState({});