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

83 lines
2.1 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';
2024-06-25 09:35:44 +01:00
import { capitalizeFirstLetter } 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';
2024-06-19 21:18:35 +01:00
2024-06-22 20:38:03 +01:00
export default function ToolLayout({
children,
title,
2024-06-23 01:26:04 +01:00
description,
2025-02-25 06:17:10 +00:00
icon,
2025-07-12 23:02:35 -07:00
type,
i18n
2024-06-22 20:38:03 +01:00
}: {
title: string;
description: string;
2025-02-25 06:17:10 +00:00
icon?: IconifyIcon | string;
2024-06-25 19:45:29 +01:00
type: string;
2024-06-22 20:38:03 +01:00
children: ReactNode;
2025-07-12 23:02:35 -07:00
i18n?: {
name: string;
description: string;
shortDescription: string;
};
2024-06-22 20:38:03 +01:00
}) {
2025-07-12 23:02:35 -07:00
const { t } = useTranslation();
// Use i18n keys if available, otherwise fall back to provided strings
2025-07-13 14:09:04 +01:00
//@ts-ignore
const toolTitle: string = i18n ? t(i18n.name) : title;
//@ts-ignore
const toolDescription: string = i18n ? t(i18n.description) : description;
2025-07-12 23:02:35 -07:00
2024-06-25 08:39:29 +01:00
const otherCategoryTools =
getToolsByCategory()
.find((category) => category.type === type)
?.tools.filter((tool) => tool.name !== title)
.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}
/>
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-12 23:02:35 -07:00
title={t('toolLayout.allToolsTitle', {
type: capitalizeFirstLetter(
getToolsByCategory().find((category) => category.type === type)!
.rawTitle
)
})}
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
}