2024-09-30 09:04:13 +02:00
|
|
|
import { useI18n } from '@/modules/i18n/i18n.provider';
|
|
|
|
import { safely } from '@corentinth/chisels';
|
|
|
|
import { useParams } from '@solidjs/router';
|
2024-10-02 22:30:45 +02:00
|
|
|
import { type Component, createResource, lazy, Show } from 'solid-js';
|
2024-09-30 09:04:13 +02:00
|
|
|
import { CurrentToolProvider } from '../tools.provider';
|
|
|
|
import { getToolDefinitionBySlug } from '../tools.registry';
|
|
|
|
|
|
|
|
export const ToolPage: Component = () => {
|
|
|
|
const params = useParams();
|
2024-10-06 11:32:23 +02:00
|
|
|
const { getLocale, t } = useI18n();
|
2024-09-30 09:04:13 +02:00
|
|
|
|
|
|
|
const toolDefinition = getToolDefinitionBySlug({ slug: params.toolSlug });
|
|
|
|
const ToolComponent = lazy(toolDefinition.entryFile);
|
|
|
|
|
|
|
|
const [toolDict] = createResource(getLocale, async (locale) => {
|
2024-10-02 22:30:45 +02:00
|
|
|
const [dict, error] = await safely(import(`../definitions/${toolDefinition.dirName}/locales/${locale}.json`));
|
2024-09-30 09:04:13 +02:00
|
|
|
|
2024-10-02 22:30:45 +02:00
|
|
|
if (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dict ?? { default: {} };
|
2024-09-30 09:04:13 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Show when={toolDict()}>
|
|
|
|
{toolLocaleDict => (
|
2024-10-06 11:32:23 +02:00
|
|
|
<CurrentToolProvider
|
|
|
|
toolLocaleDict={toolLocaleDict}
|
|
|
|
tool={() => ({
|
|
|
|
icon: toolDefinition.icon,
|
|
|
|
dirName: toolDefinition.dirName,
|
|
|
|
createdAt: toolDefinition.createdAt,
|
|
|
|
name: t(`tools.${toolDefinition.slug}.name` as any),
|
|
|
|
description: t(`tools.${toolDefinition.slug}.description` as any),
|
|
|
|
})}
|
|
|
|
>
|
2024-09-30 09:04:13 +02:00
|
|
|
<ToolComponent />
|
|
|
|
</CurrentToolProvider>
|
|
|
|
)}
|
|
|
|
</Show>
|
|
|
|
);
|
|
|
|
};
|