From 395d220db92c9a278ee1e3292ebc2d28b6af1cf9 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Tue, 15 Mar 2022 12:53:54 +0100 Subject: [PATCH 1/2] fix(profiles): getPathToContributor does not include path prefix --- src/app/profiles/App/Pages/index.tsx | 3 ++- src/app/profiles/App/pathToContributor.ts | 7 ++++--- src/libs/facets/getPathPrefix.ts | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 src/libs/facets/getPathPrefix.ts diff --git a/src/app/profiles/App/Pages/index.tsx b/src/app/profiles/App/Pages/index.tsx index 29e5f7fde..01dafd4bf 100644 --- a/src/app/profiles/App/Pages/index.tsx +++ b/src/app/profiles/App/Pages/index.tsx @@ -7,11 +7,12 @@ import Profiles from './Profiles'; import Error from './Error'; import Subscriptions from './Subscriptions'; import { getFacet } from '../../../../libs/facets/getFacet'; +import { getPathPrefix } from '../../../../libs/facets/getPathPrefix'; const Pages = () => { useChangeLanguage(); const { t, i18n } = useTranslation(); - const prefix = getFacet() === 'lmel' ? '' : `/${i18n.language}`; + const prefix = getPathPrefix(i18n); return ( <> diff --git a/src/app/profiles/App/pathToContributor.ts b/src/app/profiles/App/pathToContributor.ts index 6d74ef18f..dd5bdc104 100644 --- a/src/app/profiles/App/pathToContributor.ts +++ b/src/app/profiles/App/pathToContributor.ts @@ -1,11 +1,12 @@ import slugify from 'slugify'; import i18n from 'i18next'; import { Contributor } from 'libs/domain/contributor'; +import { getPathPrefix } from '../../../libs/facets/getPathPrefix'; const pathToContributor = (contributor: Contributor) => { - return `${i18n.t('path.profiles.contributors')}/${contributor.id}/${slugify( - contributor.name - )}`; + return `${getPathPrefix(i18n)}${i18n.t('path.profiles.contributors')}/${ + contributor.id + }/${slugify(contributor.name)}`; }; export default pathToContributor; diff --git a/src/libs/facets/getPathPrefix.ts b/src/libs/facets/getPathPrefix.ts new file mode 100644 index 000000000..4c4314d55 --- /dev/null +++ b/src/libs/facets/getPathPrefix.ts @@ -0,0 +1,5 @@ +import { i18n } from 'i18next'; +import { getFacet } from './getFacet'; + +export const getPathPrefix = (i18n: i18n): string => + getFacet() === 'lmel' ? '' : `/${i18n.language}`; From 4cb74fef36a1c994978ee864a702b1d4ac4de4b8 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Tue, 15 Mar 2022 15:08:16 +0100 Subject: [PATCH 2/2] refactor: use join-url instead on complicated string template --- package.json | 1 + src/app/profiles/App/pathToContributor.ts | 10 +++++++--- src/index.d.ts | 2 ++ yarn.lock | 5 +++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6ace002f2..a9c56164c 100644 --- a/package.json +++ b/package.json @@ -167,6 +167,7 @@ "i18next": "^19.9.2", "i18next-browser-languagedetector": "^5.0.1", "isomorphic-fetch": "^2.2.1", + "join-url": "^2.0.0", "jsdom": "^15.1.1", "jsdom-global": "^3.0.2", "koa": "^2.13.4", diff --git a/src/app/profiles/App/pathToContributor.ts b/src/app/profiles/App/pathToContributor.ts index dd5bdc104..58699279b 100644 --- a/src/app/profiles/App/pathToContributor.ts +++ b/src/app/profiles/App/pathToContributor.ts @@ -1,12 +1,16 @@ import slugify from 'slugify'; import i18n from 'i18next'; +import join from 'join-url'; import { Contributor } from 'libs/domain/contributor'; import { getPathPrefix } from '../../../libs/facets/getPathPrefix'; const pathToContributor = (contributor: Contributor) => { - return `${getPathPrefix(i18n)}${i18n.t('path.profiles.contributors')}/${ - contributor.id - }/${slugify(contributor.name)}`; + return join.pathname( + getPathPrefix(i18n), + i18n.t('path.profiles.contributors'), + contributor.id, + slugify(contributor.name) + ); }; export default pathToContributor; diff --git a/src/index.d.ts b/src/index.d.ts index c6478a19a..8c4bcd06e 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -6,3 +6,5 @@ declare module '*.mp4' { } // eslint-disable-next-line import/order declare module 'react-adobe-animate'; + +declare module 'join-url'; diff --git a/yarn.lock b/yarn.lock index 7574896df..8b19143fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10923,6 +10923,11 @@ join-component@^1.1.0: resolved "https://registry.yarnpkg.com/join-component/-/join-component-1.1.0.tgz#b8417b750661a392bee2c2537c68b2a9d4977cd5" integrity sha1-uEF7dQZho5K+4sJTfGiyqdSXfNU= +join-url@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/join-url/-/join-url-2.0.0.tgz#a80b63a58eba5b44abaf793c17c3b5817ef69e1b" + integrity sha1-qAtjpY66W0Srr3k8F8O1gX72nhs= + js-string-escape@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/js-string-escape/-/js-string-escape-1.0.1.tgz#e2625badbc0d67c7533e9edc1068c587ae4137ef"