mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-09-24 12:36:13 +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>
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import { useCallback } from 'react';
|
|
import { useToolNavigation } from './useToolNavigation';
|
|
import { useToolManagement } from './useToolManagement';
|
|
import { handleUnlessSpecialClick } from '../utils/clickHandlers';
|
|
|
|
export interface SidebarNavigationProps {
|
|
/** Full URL for the navigation (for href attribute) */
|
|
href: string;
|
|
/** Click handler that maintains SPA behavior */
|
|
onClick: (e: React.MouseEvent) => void;
|
|
}
|
|
|
|
/**
|
|
* Hook that provides URL and navigation handlers for sidebar navigation buttons
|
|
* Supports special routes like home ('/') and specific tool routes
|
|
*/
|
|
export function useSidebarNavigation(): {
|
|
getHomeNavigation: () => SidebarNavigationProps;
|
|
getToolNavigation: (toolId: string) => SidebarNavigationProps | null;
|
|
} {
|
|
const { getToolNavigation: getToolNavProps } = useToolNavigation();
|
|
const { getSelectedTool } = useToolManagement();
|
|
|
|
const defaultNavClick = useCallback((e: React.MouseEvent) => {
|
|
handleUnlessSpecialClick(e, () => {
|
|
// SPA navigation will be handled by the calling component
|
|
});
|
|
}, []);
|
|
|
|
const getHomeNavigation = useCallback((): SidebarNavigationProps => {
|
|
const href = '/'; // SSR-safe relative path
|
|
return { href, onClick: defaultNavClick };
|
|
}, [defaultNavClick]);
|
|
|
|
const getToolNavigation = useCallback((toolId: string): SidebarNavigationProps | null => {
|
|
// Handle special nav sections that aren't tools
|
|
if (toolId === 'read') return { href: '/read', onClick: defaultNavClick };
|
|
if (toolId === 'automate') return { href: '/automate', onClick: defaultNavClick };
|
|
|
|
const tool = getSelectedTool(toolId);
|
|
if (!tool) return null;
|
|
|
|
// Delegate to useToolNavigation for true tools
|
|
return getToolNavProps(toolId, tool);
|
|
}, [getToolNavProps, getSelectedTool, defaultNavClick]);
|
|
|
|
return {
|
|
getHomeNavigation,
|
|
getToolNavigation
|
|
};
|
|
} |