From 31555580cf43c8073a0025a95eb8933d45dc6590 Mon Sep 17 00:00:00 2001 From: Nathan Arthur Date: Tue, 3 Dec 2024 13:45:39 -0500 Subject: [PATCH] re-include fcbh data --- src/containers/bible/index.tsx | 13 +++++----- src/pages/[language]/bibles/index.tsx | 37 ++++++++++++++++++++------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/containers/bible/index.tsx b/src/containers/bible/index.tsx index 2e4bbd068..e25f097ed 100644 --- a/src/containers/bible/index.tsx +++ b/src/containers/bible/index.tsx @@ -18,11 +18,10 @@ import styles from './index.module.scss'; // export type BibleIndexProps = GetAudiobibleIndexDataQuery; export type BibleIndexProps = { - data: GetAudiobibleIndexDataQuery; + data: NonNullable; }; -function Bible(props: BibleIndexProps): JSX.Element { - console.log({ props }); - const versions = props.data.collections.nodes || []; +function Bible({ data }: BibleIndexProps): JSX.Element { + console.log({ data }); return (
@@ -70,7 +69,7 @@ function Bible(props: BibleIndexProps): JSX.Element { />

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

- +
); } export default withFailStates(Bible, { - useShould404: ({ data }) => !data.collections.nodes?.length, + useShould404: ({ data }) => !data.length, }); diff --git a/src/pages/[language]/bibles/index.tsx b/src/pages/[language]/bibles/index.tsx index 0e9a3fb8b..31277f1ef 100644 --- a/src/pages/[language]/bibles/index.tsx +++ b/src/pages/[language]/bibles/index.tsx @@ -11,43 +11,62 @@ import getIntl from '~lib/getIntl'; import { getLanguageIdByRoute } from '~lib/getLanguageIdByRoute'; import root from '~lib/routes'; import { getAudiobibleIndexData } from '~src/containers/bible/__generated__'; +import { getBibles } from '~src/services/fcbh/getBibles'; +import { IBibleVersion } from '~src/services/fcbh/types'; export default Bible; +type ApiBible = BibleIndexProps['data'][0]; + +function transform(bible: IBibleVersion): ApiBible { + return { + ...bible, + sequences: { + nodes: [], + }, + }; +} + export async function getStaticProps({ params, }: GetStaticPropsContext<{ language: string }>): Promise< GetStaticPropsResult > { - // const response = await getBibles().catch((e) => { - // console.log(e); - // return null; - // }); - const apiBibles = await getAudiobibleIndexData({ + const response = await getBibles().catch((e) => { + console.log(e); + return null; + }); + + const apiData = await getAudiobibleIndexData({ language: getLanguageIdByRoute(params?.language), }).catch(() => ({ collections: { nodes: [] } })); - if (!apiBibles?.collections.nodes) { + const apiBibles = apiData?.collections.nodes || []; + + if (!apiBibles) { return { notFound: true, revalidate: REVALIDATE_FAILURE, }; } + const fcbhBibles = response?.map(transform) || []; + const intl = await getIntl(getLanguageIdByRoute(params?.language)); return { props: { // versions: [...(response || []), ...apiBibles.collections.nodes].sort( // (a, b) => a.title.localeCompare(b.title), // ), - data: apiBibles, + data: [...fcbhBibles, ...apiBibles].sort((a, b) => + a.title.localeCompare(b.title), + ), title: intl.formatMessage({ id: 'bible__title', defaultMessage: 'Bible', }), }, - // revalidate: response ? REVALIDATE : REVALIDATE_FAILURE, - revalidate: REVALIDATE, + revalidate: response ? REVALIDATE : REVALIDATE_FAILURE, }; }