aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/hooks/use-settings.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-11-15 12:24:42 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-15 17:26:16 +0100
commit0f38aee374029213a47ef7c29bd164093fe63c85 (patch)
tree290cb6471fdfe81e4c42f4da4729247536b04ee7 /src/utils/hooks/use-settings.tsx
parentbe4d907efb4e2fa658baa7c9b276ed282eb920db (diff)
refactor(hooks): remove useSettings hook
It does not make sense to re-export an existing object through a hook. On some pages both the hook and the object was imported... It is better to use the CONFIG (previously settings) object directly and by doing it we avoid potential errors because of conditional hooks.
Diffstat (limited to 'src/utils/hooks/use-settings.tsx')
-rw-r--r--src/utils/hooks/use-settings.tsx95
1 files changed, 0 insertions, 95 deletions
diff --git a/src/utils/hooks/use-settings.tsx b/src/utils/hooks/use-settings.tsx
deleted file mode 100644
index 968930d..0000000
--- a/src/utils/hooks/use-settings.tsx
+++ /dev/null
@@ -1,95 +0,0 @@
-import { useRouter } from 'next/router';
-import { settings } from '../config';
-
-export type BlogSettings = {
- /**
- * The number of posts per page.
- */
- postsPerPage: number;
-};
-
-export type CopyrightSettings = {
- /**
- * The copyright end year.
- */
- end: string;
- /**
- * The copyright start year.
- */
- start: string;
-};
-
-export type LocaleSettings = {
- /**
- * The default locale.
- */
- default: string;
- /**
- * The supported locales.
- */
- supported: string[];
-};
-
-export type WebsiteSettings = {
- /**
- * The website name.
- */
- name: string;
- /**
- * The website baseline.
- */
- baseline: string;
- /**
- * The website copyright dates.
- */
- copyright: CopyrightSettings;
- /**
- * The website admin email.
- */
- email: string;
- /**
- * The website locales.
- */
- locales: LocaleSettings;
- /**
- * The website url.
- */
- url: string;
-};
-
-export type UseSettingsReturn = {
- blog: BlogSettings;
- website: WebsiteSettings;
-};
-
-/**
- * Retrieve the website and blog settings.
- *
- * @returns {UseSettingsReturn} - An object describing settings.
- */
-export const useSettings = (): UseSettingsReturn => {
- const { baseline, copyright, email, locales, name, postsPerPage, url } =
- settings;
- const router = useRouter();
- const locale = router.locale ?? locales.defaultLocale;
-
- return {
- blog: {
- postsPerPage,
- },
- website: {
- baseline: locale.startsWith('en') ? baseline.en : baseline.fr,
- copyright: {
- end: copyright.endYear,
- start: copyright.startYear,
- },
- email,
- locales: {
- default: locales.defaultLocale,
- supported: locales.supported,
- },
- name,
- url,
- },
- };
-};