From 13b1be06372ed6e59d79b5f71858c3537997a94b Mon Sep 17 00:00:00 2001 From: Nathan Arthur Date: Tue, 3 Dec 2024 13:59:29 -0500 Subject: [PATCH] abbreviate versions properly in the version selector --- src/containers/bible/index.tsx | 35 +++++----------------------------- src/lib/getBibleAcronym.ts | 18 +++++++++++++++++ 2 files changed, 23 insertions(+), 30 deletions(-) create mode 100644 src/lib/getBibleAcronym.ts diff --git a/src/containers/bible/index.tsx b/src/containers/bible/index.tsx index e25f097ed..a068ccd46 100644 --- a/src/containers/bible/index.tsx +++ b/src/containers/bible/index.tsx @@ -12,6 +12,7 @@ import Dropdown from '~src/components/molecules/dropdown'; import IconButton from '~src/components/molecules/iconButton'; import Tease from '~src/components/molecules/tease'; import PassageNavigation from '~src/components/organisms/passageNavigation'; +import { getBibleAcronym } from '~src/lib/getBibleAcronym'; import { GetAudiobibleIndexDataQuery } from './__generated__'; import styles from './index.module.scss'; @@ -43,39 +44,13 @@ function Bible({ data }: BibleIndexProps): JSX.Element { > {(handleClose) => (
- {/*

- { - e.preventDefault(); - handleClose(); - }} - > - - -

-

- { - e.preventDefault(); - handleClose(); - }} - > - - -

*/} - {data.map((audiobible) => ( -

+ {data.map((version) => ( +

- {audiobible.title} + {getBibleAcronym(version.title)}

))} diff --git a/src/lib/getBibleAcronym.ts b/src/lib/getBibleAcronym.ts new file mode 100644 index 000000000..7883f4e9e --- /dev/null +++ b/src/lib/getBibleAcronym.ts @@ -0,0 +1,18 @@ +export const getBibleAcronym = (title: string) => { + if (!title.includes('(')) { + return title + .split(' ') + .map((word) => word[0]) + .join(''); + } + const match = title.match(/(.*?)\s*\(.*?\)/); // Match text up to parenthesis + const acronym = match + ? match[1] + .split(' ') + .map((word) => word[0]) + .join('') + : ''; + const parenthesisMatch = title.match(/\((.*?)\)/); + const parenthesisContent = parenthesisMatch ? parenthesisMatch[1] : ''; // Get content inside parenthesis + return acronym + (parenthesisContent ? ` (${parenthesisContent})` : ''); // Combine acronym with content +};