2022-07-07 23:42:38 +00:00
|
|
|
import { GetStaticProps } from "next";
|
2022-07-23 08:24:13 +00:00
|
|
|
import { AppLayout, AppLayoutRequired } from "components/AppLayout";
|
2022-05-14 12:45:29 +00:00
|
|
|
import { PanelHeader } from "components/PanelComponents/PanelHeader";
|
2022-10-29 14:22:49 +00:00
|
|
|
import { SubPanel } from "components/Containers/SubPanel";
|
2022-07-18 00:04:13 +00:00
|
|
|
import { getReadySdk } from "graphql/sdk";
|
|
|
|
import { GetChroniclesChaptersQuery } from "graphql/generated";
|
2022-12-09 22:03:09 +00:00
|
|
|
import { filterHasAttributes } from "helpers/asserts";
|
2022-07-18 00:04:13 +00:00
|
|
|
import { prettySlug } from "helpers/formatters";
|
2022-07-23 08:24:13 +00:00
|
|
|
import { getOpenGraph } from "helpers/openGraph";
|
2022-08-15 22:17:26 +00:00
|
|
|
import { TranslatedChroniclesList } from "components/Chronicles/ChroniclesList";
|
2022-08-22 19:56:00 +00:00
|
|
|
import { HorizontalLine } from "components/HorizontalLine";
|
2022-08-27 15:03:05 +00:00
|
|
|
import { getLangui } from "graphql/fetchLocalData";
|
2022-11-04 01:30:20 +00:00
|
|
|
import { atoms } from "contexts/atoms";
|
|
|
|
import { useAtomGetter } from "helpers/atoms";
|
2021-11-06 16:47:20 +00:00
|
|
|
|
2022-07-03 12:34:00 +00:00
|
|
|
/*
|
|
|
|
* ╭────────╮
|
|
|
|
* ──────────────────────────────────────────╯ PAGE ╰─────────────────────────────────────────────
|
|
|
|
*/
|
|
|
|
|
2022-08-27 15:03:05 +00:00
|
|
|
interface Props extends AppLayoutRequired {
|
2022-08-28 15:40:41 +00:00
|
|
|
chapters: NonNullable<GetChroniclesChaptersQuery["chroniclesChapters"]>["data"];
|
2022-07-18 00:04:13 +00:00
|
|
|
}
|
2022-02-12 10:02:22 +00:00
|
|
|
|
2022-08-27 15:03:05 +00:00
|
|
|
const Chronicles = ({ chapters, ...otherProps }: Props): JSX.Element => {
|
2022-11-04 01:30:20 +00:00
|
|
|
const langui = useAtomGetter(atoms.localData.langui);
|
2022-12-04 14:31:11 +00:00
|
|
|
const subPanel = (
|
|
|
|
<SubPanel>
|
|
|
|
<PanelHeader
|
2023-01-07 00:59:54 +00:00
|
|
|
icon="schedule"
|
2022-12-04 14:31:11 +00:00
|
|
|
title={langui.chronicles}
|
|
|
|
description={langui.chronicles_description}
|
|
|
|
/>
|
2022-08-22 19:56:00 +00:00
|
|
|
|
2022-12-04 14:31:11 +00:00
|
|
|
<HorizontalLine />
|
2022-08-22 19:56:00 +00:00
|
|
|
|
2022-12-04 14:31:11 +00:00
|
|
|
<div className="grid gap-16">
|
|
|
|
{filterHasAttributes(chapters, ["attributes.chronicles", "id"] as const).map((chapter) => (
|
|
|
|
<TranslatedChroniclesList
|
|
|
|
key={chapter.id}
|
|
|
|
chronicles={chapter.attributes.chronicles.data}
|
|
|
|
translations={filterHasAttributes(chapter.attributes.titles, [
|
|
|
|
"language.data.attributes.code",
|
|
|
|
] as const).map((translation) => ({
|
|
|
|
title: translation.title,
|
|
|
|
language: translation.language.data.attributes.code,
|
|
|
|
}))}
|
|
|
|
fallback={{ title: prettySlug(chapter.attributes.slug) }}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</SubPanel>
|
2021-11-13 20:26:18 +00:00
|
|
|
);
|
2022-06-22 22:39:59 +00:00
|
|
|
|
2022-08-27 15:03:05 +00:00
|
|
|
return <AppLayout subPanel={subPanel} {...otherProps} />;
|
2022-07-03 12:34:00 +00:00
|
|
|
};
|
|
|
|
export default Chronicles;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ╭──────────────────────╮
|
|
|
|
* ───────────────────────────────────╯ NEXT DATA FETCHING ╰──────────────────────────────────────
|
|
|
|
*/
|
2022-02-12 10:02:22 +00:00
|
|
|
|
2022-07-03 12:34:00 +00:00
|
|
|
export const getStaticProps: GetStaticProps = async (context) => {
|
2022-07-18 00:04:13 +00:00
|
|
|
const sdk = getReadySdk();
|
2022-08-27 15:03:05 +00:00
|
|
|
const langui = getLangui(context.locale);
|
2022-07-18 00:04:13 +00:00
|
|
|
const chronicles = await sdk.getChroniclesChapters();
|
|
|
|
if (!chronicles.chroniclesChapters?.data) return { notFound: true };
|
2022-08-27 15:03:05 +00:00
|
|
|
|
2022-04-03 08:34:21 +00:00
|
|
|
const props: Props = {
|
2022-07-18 00:04:13 +00:00
|
|
|
chapters: chronicles.chroniclesChapters.data,
|
2022-08-27 15:03:05 +00:00
|
|
|
openGraph: getOpenGraph(langui, langui.chronicles ?? "Chronicles"),
|
2022-03-07 14:50:00 +00:00
|
|
|
};
|
|
|
|
return {
|
|
|
|
props: props,
|
|
|
|
};
|
2022-07-03 12:34:00 +00:00
|
|
|
};
|