Files
Stirling-PDF/frontend/src/components/tools/shared/renderToolButtons.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-09-05 12:16:17 +01:00
import { Box } from '@mantine/core';
2025-08-22 14:40:27 +01:00
import ToolButton from '../toolPicker/ToolButton';
import SubcategoryHeader from './SubcategoryHeader';
import { getSubcategoryLabel } from "../../../data/toolsTaxonomy";
import { TFunction } from 'i18next';
import { SubcategoryGroup } from '../../../hooks/useToolSections';
import { ToolId } from 'src/types/toolId';
2025-08-22 14:40:27 +01:00
// Helper function to render tool buttons for a subcategory
export const renderToolButtons = (
t: TFunction,
subcategory: SubcategoryGroup,
selectedToolKey: string | null,
onSelect: (id: ToolId) => void,
2025-09-05 17:12:52 +01:00
showSubcategoryHeader: boolean = true,
2025-09-25 16:32:30 +01:00
disableNavigation: boolean = false,
2025-10-10 15:36:35 +01:00
searchResults?: Array<{ item: [string, any]; matchedText?: string }>,
hasStars: boolean = false
2025-09-25 16:32:30 +01:00
) => {
// Create a map of matched text for quick lookup
const matchedTextMap = new Map<string, string>();
if (searchResults) {
searchResults.forEach(({ item: [id], matchedText }) => {
if (matchedText) matchedTextMap.set(id, matchedText);
});
}
return (
<Box key={subcategory.subcategoryId} w="100%">
{showSubcategoryHeader && (
<SubcategoryHeader label={getSubcategoryLabel(t, subcategory.subcategoryId)} />
)}
<div>
{subcategory.tools.map(({ id, tool }) => {
const matchedSynonym = matchedTextMap.get(id);
2025-09-25 16:32:30 +01:00
return (
<ToolButton
key={id}
id={id}
tool={tool}
isSelected={selectedToolKey === id}
onSelect={onSelect}
disableNavigation={disableNavigation}
matchedSynonym={matchedSynonym}
2025-10-10 15:36:35 +01:00
hasStars={hasStars}
2025-09-25 16:32:30 +01:00
/>
);
})}
</div>
</Box>
);
};