Files
omni-tools/src/components/ToolLayout.tsx

90 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-06-22 20:38:03 +01:00
import { Box } from '@mui/material';
import React, { ReactNode } from 'react';
import { Helmet } from 'react-helmet';
import ToolHeader from './ToolHeader';
2024-06-27 12:39:38 +01:00
import Separator from './Separator';
2024-06-25 08:39:29 +01:00
import AllTools from './allTools/AllTools';
import { getToolsByCategory } from '@tools/index';
2025-07-14 14:51:46 +01:00
import {
capitalizeFirstLetter,
getI18nNamespaceFromToolCategory
} from '../utils/string';
2025-02-25 06:17:10 +00:00
import { IconifyIcon } from '@iconify/react';
2025-07-12 23:02:35 -07:00
import { useTranslation } from 'react-i18next';
2025-07-13 15:39:12 +01:00
import { ToolCategory } from '@tools/defineTool';
import { FullI18nKey } from '../i18n';
2024-06-19 21:18:35 +01:00
2024-06-22 20:38:03 +01:00
export default function ToolLayout({
children,
2025-02-25 06:17:10 +00:00
icon,
i18n,
2025-07-14 14:01:54 +12:00
type,
2025-07-15 14:01:38 +01:00
fullPath
2024-06-22 20:38:03 +01:00
}: {
2025-02-25 06:17:10 +00:00
icon?: IconifyIcon | string;
2025-07-13 15:39:12 +01:00
type: ToolCategory;
2025-07-15 14:01:38 +01:00
fullPath: string;
2024-06-22 20:38:03 +01:00
children: ReactNode;
2025-07-12 23:02:35 -07:00
i18n?: {
2025-07-13 15:39:12 +01:00
name: FullI18nKey;
description: FullI18nKey;
shortDescription: FullI18nKey;
2025-07-12 23:02:35 -07:00
};
2024-06-22 20:38:03 +01:00
}) {
2025-07-14 14:51:46 +01:00
const { t } = useTranslation([
'translation',
getI18nNamespaceFromToolCategory(type)
]);
2025-07-12 23:02:35 -07:00
// Use i18n keys if available, otherwise fall back to provided strings
2025-07-13 14:09:04 +01:00
//@ts-ignore
2025-07-14 18:04:30 +01:00
const toolTitle: string = t(i18n.name);
2025-07-13 14:09:04 +01:00
//@ts-ignore
2025-07-14 18:04:30 +01:00
const toolDescription: string = t(i18n.description);
2025-07-12 23:02:35 -07:00
2024-06-25 08:39:29 +01:00
const otherCategoryTools =
2025-07-15 18:30:02 +01:00
getToolsByCategory(t)
2024-06-25 08:39:29 +01:00
.find((category) => category.type === type)
2025-07-14 18:04:30 +01:00
?.tools.filter((tool) => t(tool.name) !== toolTitle)
2024-06-25 08:39:29 +01:00
.map((tool) => ({
title: tool.name,
description: tool.shortDescription,
2025-03-02 17:28:45 +00:00
link: '/' + tool.path,
icon: tool.icon
2024-06-25 08:39:29 +01:00
})) ?? [];
2024-06-22 20:38:03 +01:00
return (
<Box
width={'100%'}
display={'flex'}
flexDirection={'column'}
alignItems={'center'}
2025-03-31 01:27:44 +00:00
sx={{ backgroundColor: 'background.default' }}
2024-06-22 20:38:03 +01:00
>
<Helmet>
2025-07-12 23:02:35 -07:00
<title>{`${toolTitle} - OmniTools`}</title>
2024-06-22 20:38:03 +01:00
</Helmet>
<Box width={'85%'}>
2024-06-25 19:45:29 +01:00
<ToolHeader
2025-07-12 23:02:35 -07:00
title={toolTitle}
description={toolDescription}
2025-02-25 06:17:10 +00:00
icon={icon}
2024-06-25 19:45:29 +01:00
type={type}
2025-07-15 14:01:38 +01:00
path={fullPath}
2024-06-25 19:45:29 +01:00
/>
2024-06-22 20:38:03 +01:00
{children}
2024-06-25 08:39:29 +01:00
<Separator backgroundColor="#5581b5" margin="50px" />
2024-06-25 09:35:44 +01:00
<AllTools
2025-07-15 19:58:56 +01:00
title={t('translation:toolLayout.allToolsTitle', '', {
2025-07-12 23:02:35 -07:00
type: capitalizeFirstLetter(
2025-07-15 18:30:02 +01:00
getToolsByCategory(t).find((category) => category.type === type)!
.title
2025-07-12 23:02:35 -07:00
)
})}
2024-06-25 09:35:44 +01:00
toolCards={otherCategoryTools}
/>
2024-06-22 20:38:03 +01:00
</Box>
</Box>
);
2024-06-19 21:18:35 +01:00
}