Contents only have one folder now
This commit is contained in:
parent
57ba34aae3
commit
93645a2f53
|
@ -5,6 +5,7 @@ import { NavOption } from "./PanelComponents/NavOption";
|
||||||
import { ChroniclePreview } from "./Chronicles/ChroniclePreview";
|
import { ChroniclePreview } from "./Chronicles/ChroniclePreview";
|
||||||
import { ChroniclesList } from "./Chronicles/ChroniclesList";
|
import { ChroniclesList } from "./Chronicles/ChroniclesList";
|
||||||
import { Button } from "./Inputs/Button";
|
import { Button } from "./Inputs/Button";
|
||||||
|
import { ReturnButton } from "./PanelComponents/ReturnButton";
|
||||||
import { useSmartLanguage } from "hooks/useSmartLanguage";
|
import { useSmartLanguage } from "hooks/useSmartLanguage";
|
||||||
import { PreviewFolder } from "pages/contents/folder/[slug]";
|
import { PreviewFolder } from "pages/contents/folder/[slug]";
|
||||||
|
|
||||||
|
@ -200,3 +201,26 @@ export const TranslatedPreviewFolder = ({
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
|
||||||
|
|
||||||
|
export const TranslatedReturnButton = ({
|
||||||
|
translations,
|
||||||
|
fallback,
|
||||||
|
...otherProps
|
||||||
|
}: TranslatedProps<
|
||||||
|
Parameters<typeof ReturnButton>[0],
|
||||||
|
"title"
|
||||||
|
>): JSX.Element => {
|
||||||
|
const [selectedTranslation] = useSmartLanguage({
|
||||||
|
items: translations,
|
||||||
|
languageExtractor,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ReturnButton
|
||||||
|
title={selectedTranslation?.title ?? fallback.title}
|
||||||
|
{...otherProps}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -214,9 +214,8 @@ query getContentText($slug: String, $language_code: String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
folders(pagination: { limit: -1 }) {
|
folder {
|
||||||
data {
|
data {
|
||||||
id
|
|
||||||
attributes {
|
attributes {
|
||||||
slug
|
slug
|
||||||
titles(pagination: { limit: -1 }) {
|
titles(pagination: { limit: -1 }) {
|
||||||
|
|
|
@ -35,6 +35,9 @@ type HookContent = {
|
||||||
model: "content";
|
model: "content";
|
||||||
entry: {
|
entry: {
|
||||||
slug: string;
|
slug: string;
|
||||||
|
folder?: {
|
||||||
|
slug: string;
|
||||||
|
};
|
||||||
ranged_contents: {
|
ranged_contents: {
|
||||||
slug: string;
|
slug: string;
|
||||||
}[];
|
}[];
|
||||||
|
@ -160,9 +163,15 @@ const Revalidate = (
|
||||||
case "content": {
|
case "content": {
|
||||||
paths.push(`/contents`);
|
paths.push(`/contents`);
|
||||||
paths.push(`/contents/${body.entry.slug}`);
|
paths.push(`/contents/${body.entry.slug}`);
|
||||||
|
if (body.entry.folder?.slug) {
|
||||||
|
paths.push(`/contents/folder/${body.entry.folder.slug}`);
|
||||||
|
}
|
||||||
serverRuntimeConfig.locales?.forEach((locale: string) => {
|
serverRuntimeConfig.locales?.forEach((locale: string) => {
|
||||||
paths.push(`/${locale}/contents`);
|
paths.push(`/${locale}/contents`);
|
||||||
paths.push(`/${locale}/contents/${body.entry.slug}`);
|
paths.push(`/${locale}/contents/${body.entry.slug}`);
|
||||||
|
if (body.entry.folder?.slug) {
|
||||||
|
paths.push(`/${locale}/contents/folder/${body.entry.folder.slug}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (body.entry.ranged_contents.length > 0) {
|
if (body.entry.ranged_contents.length > 0) {
|
||||||
body.entry.ranged_contents.forEach((ranged_content) => {
|
body.entry.ranged_contents.forEach((ranged_content) => {
|
||||||
|
|
|
@ -5,10 +5,7 @@ import { Chip } from "components/Chip";
|
||||||
import { HorizontalLine } from "components/HorizontalLine";
|
import { HorizontalLine } from "components/HorizontalLine";
|
||||||
import { PreviewCardCTAs } from "components/Library/PreviewCardCTAs";
|
import { PreviewCardCTAs } from "components/Library/PreviewCardCTAs";
|
||||||
import { Markdawn, TableOfContents } from "components/Markdown/Markdawn";
|
import { Markdawn, TableOfContents } from "components/Markdown/Markdawn";
|
||||||
import {
|
import { ReturnButtonType } from "components/PanelComponents/ReturnButton";
|
||||||
ReturnButton,
|
|
||||||
ReturnButtonType,
|
|
||||||
} from "components/PanelComponents/ReturnButton";
|
|
||||||
import { ContentPanel } from "components/Panels/ContentPanel";
|
import { ContentPanel } from "components/Panels/ContentPanel";
|
||||||
import { SubPanel } from "components/Panels/SubPanel";
|
import { SubPanel } from "components/Panels/SubPanel";
|
||||||
import { PreviewCard } from "components/PreviewCard";
|
import { PreviewCard } from "components/PreviewCard";
|
||||||
|
@ -34,8 +31,8 @@ import { useMediaMobile } from "hooks/useMediaQuery";
|
||||||
import { AnchorIds, useScrollTopOnChange } from "hooks/useScrollTopOnChange";
|
import { AnchorIds, useScrollTopOnChange } from "hooks/useScrollTopOnChange";
|
||||||
import { useSmartLanguage } from "hooks/useSmartLanguage";
|
import { useSmartLanguage } from "hooks/useSmartLanguage";
|
||||||
import {
|
import {
|
||||||
TranslatedPreviewFolder,
|
|
||||||
TranslatedPreviewLine,
|
TranslatedPreviewLine,
|
||||||
|
TranslatedReturnButton,
|
||||||
} from "components/Translated";
|
} from "components/Translated";
|
||||||
import { getOpenGraph } from "helpers/openGraph";
|
import { getOpenGraph } from "helpers/openGraph";
|
||||||
import {
|
import {
|
||||||
|
@ -78,50 +75,56 @@ const Content = ({
|
||||||
const { previousContent, nextContent } = useMemo(
|
const { previousContent, nextContent } = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
previousContent:
|
previousContent:
|
||||||
content.folders?.data[0]?.attributes?.contents &&
|
content.folder?.data?.attributes?.contents &&
|
||||||
content.folders.data[0].attributes.sequence
|
content.folder.data.attributes.sequence
|
||||||
? getPreviousContent(
|
? getPreviousContent(
|
||||||
content.folders.data[0].attributes.contents.data,
|
content.folder.data.attributes.contents.data,
|
||||||
content.slug
|
content.slug
|
||||||
)
|
)
|
||||||
: undefined,
|
: undefined,
|
||||||
nextContent:
|
nextContent:
|
||||||
content.folders?.data[0]?.attributes?.contents &&
|
content.folder?.data?.attributes?.contents &&
|
||||||
content.folders.data[0].attributes.sequence
|
content.folder.data.attributes.sequence
|
||||||
? getNextContent(
|
? getNextContent(
|
||||||
content.folders.data[0].attributes.contents.data,
|
content.folder.data.attributes.contents.data,
|
||||||
content.slug
|
content.slug
|
||||||
)
|
)
|
||||||
: undefined,
|
: undefined,
|
||||||
}),
|
}),
|
||||||
[content.folders, content.slug]
|
[content.folder, content.slug]
|
||||||
|
);
|
||||||
|
|
||||||
|
const returnButtonProps = useMemo(
|
||||||
|
() => ({
|
||||||
|
href: content.folder?.data?.attributes
|
||||||
|
? `/contents/folder/${content.folder.data.attributes.slug}`
|
||||||
|
: "/contents",
|
||||||
|
|
||||||
|
translations: filterHasAttributes(
|
||||||
|
content.folder?.data?.attributes?.titles,
|
||||||
|
["language.data.attributes.code"] as const
|
||||||
|
).map((title) => ({
|
||||||
|
language: title.language.data.attributes.code,
|
||||||
|
title: title.title,
|
||||||
|
})),
|
||||||
|
fallback: {
|
||||||
|
title: content.folder?.data?.attributes
|
||||||
|
? prettySlug(content.folder.data.attributes.slug)
|
||||||
|
: langui.contents,
|
||||||
|
},
|
||||||
|
langui,
|
||||||
|
}),
|
||||||
|
[content.folder?.data?.attributes, langui]
|
||||||
);
|
);
|
||||||
|
|
||||||
const subPanel = useMemo(
|
const subPanel = useMemo(
|
||||||
() => (
|
() => (
|
||||||
<SubPanel>
|
<SubPanel>
|
||||||
{content.folders?.data && content.folders.data.length > 0 && (
|
<TranslatedReturnButton
|
||||||
<>
|
{...returnButtonProps}
|
||||||
<h2 className="mb-2 text-xl">{langui.folders}</h2>
|
displayOn={ReturnButtonType.Desktop}
|
||||||
{filterHasAttributes(content.folders.data, [
|
horizontalLine
|
||||||
"attributes",
|
|
||||||
"id",
|
|
||||||
] as const).map((folder) => (
|
|
||||||
<TranslatedPreviewFolder
|
|
||||||
key={folder.id}
|
|
||||||
href={`/contents/folder/${folder.attributes.slug}`}
|
|
||||||
translations={filterHasAttributes(folder.attributes.titles, [
|
|
||||||
"language.data.attributes.code",
|
|
||||||
] as const).map((title) => ({
|
|
||||||
language: title.language.data.attributes.code,
|
|
||||||
title: title.title,
|
|
||||||
}))}
|
|
||||||
fallback={{ title: prettySlug(folder.attributes.slug) }}
|
|
||||||
/>
|
/>
|
||||||
))}
|
|
||||||
<HorizontalLine />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{selectedTranslation?.text_set?.source_language?.data?.attributes
|
{selectedTranslation?.text_set?.source_language?.data?.attributes
|
||||||
?.code !== undefined && (
|
?.code !== undefined && (
|
||||||
|
@ -330,11 +333,11 @@ const Content = ({
|
||||||
</SubPanel>
|
</SubPanel>
|
||||||
),
|
),
|
||||||
[
|
[
|
||||||
content.folders?.data,
|
|
||||||
content.ranged_contents?.data,
|
content.ranged_contents?.data,
|
||||||
currencies,
|
currencies,
|
||||||
languages,
|
languages,
|
||||||
langui,
|
langui,
|
||||||
|
returnButtonProps,
|
||||||
selectedTranslation,
|
selectedTranslation,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -342,10 +345,8 @@ const Content = ({
|
||||||
const contentPanel = useMemo(
|
const contentPanel = useMemo(
|
||||||
() => (
|
() => (
|
||||||
<ContentPanel>
|
<ContentPanel>
|
||||||
<ReturnButton
|
<TranslatedReturnButton
|
||||||
href={`/contents/folder`}
|
{...returnButtonProps}
|
||||||
title={langui.contents}
|
|
||||||
langui={langui}
|
|
||||||
displayOn={ReturnButtonType.Mobile}
|
displayOn={ReturnButtonType.Mobile}
|
||||||
className="mb-10"
|
className="mb-10"
|
||||||
/>
|
/>
|
||||||
|
@ -481,6 +482,7 @@ const Content = ({
|
||||||
langui,
|
langui,
|
||||||
nextContent?.attributes,
|
nextContent?.attributes,
|
||||||
previousContent?.attributes,
|
previousContent?.attributes,
|
||||||
|
returnButtonProps,
|
||||||
selectedTranslation?.description,
|
selectedTranslation?.description,
|
||||||
selectedTranslation?.pre_title,
|
selectedTranslation?.pre_title,
|
||||||
selectedTranslation?.subtitle,
|
selectedTranslation?.subtitle,
|
||||||
|
@ -605,7 +607,7 @@ export const getStaticPaths: GetStaticPaths = async (context) => {
|
||||||
type FolderContents = NonNullable<
|
type FolderContents = NonNullable<
|
||||||
NonNullable<
|
NonNullable<
|
||||||
NonNullable<
|
NonNullable<
|
||||||
NonNullable<ContentWithTranslations["folders"]>["data"][number]
|
NonNullable<ContentWithTranslations["folder"]>["data"]
|
||||||
>["attributes"]
|
>["attributes"]
|
||||||
>["contents"]
|
>["contents"]
|
||||||
>["data"];
|
>["data"];
|
||||||
|
|
Loading…
Reference in New Issue