mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 03:20:46 +02:00
Restructure frontend code to allow for extensions (#4721)
# Description of Changes Move frontend code into `core` folder and add infrastructure for `proprietary` folder to include premium, non-OSS features
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { useCallback } from 'react';
|
||||
import { ToolRegistryEntry, getToolUrlPath } from '@app/data/toolsTaxonomy';
|
||||
import { useToolWorkflow } from '@app/contexts/ToolWorkflowContext';
|
||||
import { handleUnlessSpecialClick } from '@app/utils/clickHandlers';
|
||||
import { ToolId } from '@app/types/toolId';
|
||||
|
||||
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);
|
||||
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 as ToolId);
|
||||
});
|
||||
};
|
||||
|
||||
return { href, onClick };
|
||||
}, [handleToolSelect]);
|
||||
|
||||
return { getToolNavigation };
|
||||
}
|
||||
Reference in New Issue
Block a user