Skip to content

Commit

Permalink
re-include fcbh data
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Dec 3, 2024
1 parent 6453436 commit 3155558
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
13 changes: 6 additions & 7 deletions src/containers/bible/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import styles from './index.module.scss';

// export type BibleIndexProps = GetAudiobibleIndexDataQuery;
export type BibleIndexProps = {
data: GetAudiobibleIndexDataQuery;
data: NonNullable<GetAudiobibleIndexDataQuery['collections']['nodes']>;
};
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 (
<Tease className={styles.base}>
<div className={styles.hat}>
Expand Down Expand Up @@ -70,7 +69,7 @@ function Bible(props: BibleIndexProps): JSX.Element {
/>
</a>
</p> */}
{versions.map((audiobible) => (
{data.map((audiobible) => (
<p key={audiobible.id}>
<a
href={`https://www.example.com/${audiobible.id}`}
Expand All @@ -94,12 +93,12 @@ function Bible(props: BibleIndexProps): JSX.Element {
</div>

<div className={styles.content}>
<PassageNavigation books={versions[0].sequences.nodes || []} />
<PassageNavigation books={data[0].sequences.nodes || []} />
</div>
</Tease>
);
}

export default withFailStates(Bible, {
useShould404: ({ data }) => !data.collections.nodes?.length,
useShould404: ({ data }) => !data.length,
});
37 changes: 28 additions & 9 deletions src/pages/[language]/bibles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<BibleIndexProps & IBaseProps>
> {
// 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,
};
}

Expand Down

0 comments on commit 3155558

Please sign in to comment.