mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-09-18 09:29:24 +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>
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { useCallback } from 'react';
|
|
import { ToolRegistryEntry, getToolUrlPath } from '../data/toolsTaxonomy';
|
|
import { useToolWorkflow } from '../contexts/ToolWorkflowContext';
|
|
import { handleUnlessSpecialClick } from '../utils/clickHandlers';
|
|
|
|
export interface ToolNavigationProps {
|
|
/** Full URL for the tool (for href attribute) */
|
|
href: string;
|
|
/** Click handler that maintains SPA behavior */
|
|
onClick: (e: React.MouseEvent) => void;
|
|
}
|
|
|
|
/**
|
|
* Hook that provides URL and navigation handlers for tools
|
|
* Enables right-click "Open in New Tab" while maintaining SPA behavior for regular clicks
|
|
*/
|
|
export function useToolNavigation(): {
|
|
getToolNavigation: (toolId: string, tool: ToolRegistryEntry) => ToolNavigationProps;
|
|
} {
|
|
const { handleToolSelect } = useToolWorkflow();
|
|
|
|
const getToolNavigation = useCallback((toolId: string, tool: ToolRegistryEntry): ToolNavigationProps => {
|
|
// Generate SSR-safe relative path
|
|
const path = getToolUrlPath(toolId, tool);
|
|
const href = path; // Relative path, no window.location needed
|
|
|
|
// Click handler that maintains SPA behavior
|
|
const onClick = (e: React.MouseEvent) => {
|
|
handleUnlessSpecialClick(e, () => {
|
|
// Handle external links normally
|
|
if (tool.link) {
|
|
window.open(tool.link, '_blank', 'noopener,noreferrer');
|
|
return;
|
|
}
|
|
|
|
// Use SPA navigation for internal tools
|
|
handleToolSelect(toolId);
|
|
});
|
|
};
|
|
|
|
return { href, onClick };
|
|
}, [handleToolSelect]);
|
|
|
|
return { getToolNavigation };
|
|
} |