mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-09-23 12:06:14 +00:00

# Description of Changes <!-- Please provide a summary of the changes, including: - What was changed - Why the change was made - Any challenges encountered Closes #(issue_number) --> --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: ConnorYoh <40631091+ConnorYoh@users.noreply.github.com>
79 lines
2.1 KiB
TypeScript
79 lines
2.1 KiB
TypeScript
import { useMemo } from 'react';
|
|
import { useNavigationState } from '../contexts/NavigationContext';
|
|
import { useToolNavigation } from './useToolNavigation';
|
|
import { useToolManagement } from './useToolManagement';
|
|
import { ToolId } from '../types/toolId';
|
|
|
|
// Material UI Icons
|
|
import CompressIcon from '@mui/icons-material/Compress';
|
|
import SwapHorizIcon from '@mui/icons-material/SwapHoriz';
|
|
import CleaningServicesIcon from '@mui/icons-material/CleaningServices';
|
|
import CropIcon from '@mui/icons-material/Crop';
|
|
import TextFieldsIcon from '@mui/icons-material/TextFields';
|
|
|
|
export interface SuggestedTool {
|
|
id: ToolId;
|
|
title: string;
|
|
icon: React.ComponentType<any>;
|
|
href: string;
|
|
onClick: (e: React.MouseEvent) => void;
|
|
}
|
|
|
|
const ALL_SUGGESTED_TOOLS: Omit<SuggestedTool, 'href' | 'onClick'>[] = [
|
|
{
|
|
id: 'compress',
|
|
title: 'Compress',
|
|
icon: CompressIcon
|
|
},
|
|
{
|
|
id: 'convert',
|
|
title: 'Convert',
|
|
icon: SwapHorizIcon
|
|
},
|
|
{
|
|
id: 'sanitize',
|
|
title: 'Sanitize',
|
|
icon: CleaningServicesIcon
|
|
},
|
|
{
|
|
id: 'split',
|
|
title: 'Split',
|
|
icon: CropIcon
|
|
},
|
|
{
|
|
id: 'ocr',
|
|
title: 'OCR',
|
|
icon: TextFieldsIcon
|
|
}
|
|
];
|
|
|
|
export function useSuggestedTools(): SuggestedTool[] {
|
|
const { selectedTool } = useNavigationState();
|
|
const { getToolNavigation } = useToolNavigation();
|
|
const { getSelectedTool } = useToolManagement();
|
|
|
|
return useMemo(() => {
|
|
// Filter out the current tool
|
|
const filteredTools = ALL_SUGGESTED_TOOLS.filter(tool => tool.id !== selectedTool);
|
|
|
|
// Add navigation props to each tool
|
|
return filteredTools.map(tool => {
|
|
const toolRegistryEntry = getSelectedTool(tool.id);
|
|
if (!toolRegistryEntry) {
|
|
// Fallback for tools not in registry
|
|
return {
|
|
...tool,
|
|
href: `/${tool.id}`,
|
|
onClick: (e: React.MouseEvent) => { e.preventDefault(); }
|
|
};
|
|
}
|
|
|
|
const navProps = getToolNavigation(tool.id, toolRegistryEntry);
|
|
return {
|
|
...tool,
|
|
...navProps
|
|
};
|
|
});
|
|
}, [selectedTool, getToolNavigation, getSelectedTool]);
|
|
}
|