aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/hooks
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-09-26 15:54:28 +0200
committerArmand Philippot <git@armandphilippot.com>2023-10-24 12:23:48 +0200
commit70efcfeaa0603415dd992cb662d8efb960e6e49a (patch)
tree5d37e98fae9aa7e5c3d8ef30a10db9fed9b63e36 /src/utils/hooks
parent31695306bfed44409f03006ea717fd2cceff8f87 (diff)
refactor(routes): replace hardcoded routes with constants
It makes it easier to change a route if needed and it avoid typo mistakes. I also refactored a bit the concerned files to be complient with the new ESlint config. However, I should rewrite the pages to reduce the number of statements.
Diffstat (limited to 'src/utils/hooks')
-rw-r--r--src/utils/hooks/use-breadcrumb.ts (renamed from src/utils/hooks/use-breadcrumb.tsx)24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/utils/hooks/use-breadcrumb.tsx b/src/utils/hooks/use-breadcrumb.ts
index f4506d7..5839299 100644
--- a/src/utils/hooks/use-breadcrumb.tsx
+++ b/src/utils/hooks/use-breadcrumb.ts
@@ -1,6 +1,8 @@
+/* eslint-disable max-statements */
import { useIntl } from 'react-intl';
-import { BreadcrumbList } from 'schema-dts';
-import { BreadcrumbItem } from '../../components';
+import type { BreadcrumbList } from 'schema-dts';
+import type { BreadcrumbItem } from '../../components';
+import { ROUTES } from '../constants';
import { slugify } from '../helpers';
import { useSettings } from './use-settings';
@@ -38,13 +40,13 @@ export const useBreadcrumb = ({
}: useBreadcrumbProps): useBreadcrumbReturn => {
const intl = useIntl();
const { website } = useSettings();
- const isArticle = url.startsWith('/article/');
+ const isArticle = url.startsWith(`${ROUTES.ARTICLE}/`);
const isHome = url === '/';
const isPageNumber = url.includes('/page/');
- const isProject = url.startsWith('/projets/');
- const isSearch = url.startsWith('/recherche');
- const isThematic = url.startsWith('/thematique/');
- const isTopic = url.startsWith('/sujet/');
+ const isProject = url.startsWith(`${ROUTES.PROJECTS}/`);
+ const isSearch = url.startsWith(ROUTES.SEARCH);
+ const isThematic = url.startsWith(`${ROUTES.THEMATICS.INDEX}/`);
+ const isTopic = url.startsWith(`${ROUTES.TOPICS}/`);
const homeLabel = intl.formatMessage({
defaultMessage: 'Home',
@@ -69,12 +71,12 @@ export const useBreadcrumb = ({
description: 'Breadcrumb: blog label',
id: 'Es52wh',
});
- items.push({ id: 'blog', name: blogLabel, url: '/blog' });
+ items.push({ id: 'blog', name: blogLabel, url: ROUTES.BLOG });
schema.push({
'@type': 'ListItem',
position: 2,
name: blogLabel,
- item: `${website.url}/blog`,
+ item: `${website.url}${ROUTES.BLOG}`,
});
}
@@ -84,12 +86,12 @@ export const useBreadcrumb = ({
description: 'Breadcrumb: projects label',
id: '28GZdv',
});
- items.push({ id: 'blog', name: projectsLabel, url: '/projets' });
+ items.push({ id: 'projects', name: projectsLabel, url: ROUTES.PROJECTS });
schema.push({
'@type': 'ListItem',
position: 2,
name: projectsLabel,
- item: `${website.url}/projets`,
+ item: `${website.url}${ROUTES.PROJECTS}`,
});
}