Moved content functions to separate helper file
This commit is contained in:
parent
ed7198807f
commit
88b9fa4477
31
src/helpers/contents.ts
Normal file
31
src/helpers/contents.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { ContentWithTranslations, Immutable } from "./types";
|
||||||
|
|
||||||
|
type Group = Immutable<
|
||||||
|
NonNullable<
|
||||||
|
NonNullable<
|
||||||
|
NonNullable<
|
||||||
|
NonNullable<ContentWithTranslations["group"]>["data"]
|
||||||
|
>["attributes"]
|
||||||
|
>["contents"]
|
||||||
|
>["data"]
|
||||||
|
>;
|
||||||
|
|
||||||
|
export function getPreviousContent(group: Group, currentSlug: string) {
|
||||||
|
for (let index = 0; index < group.length; index += 1) {
|
||||||
|
const content = group[index];
|
||||||
|
if (content.attributes?.slug === currentSlug && index > 0) {
|
||||||
|
return group[index - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getNextContent(group: Group, currentSlug: string) {
|
||||||
|
for (let index = 0; index < group.length; index += 1) {
|
||||||
|
const content = group[index];
|
||||||
|
if (content.attributes?.slug === currentSlug && index < group.length - 1) {
|
||||||
|
return group[index + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
@ -15,6 +15,7 @@ import { ThumbnailHeader } from "components/ThumbnailHeader";
|
|||||||
import { ToolTip } from "components/ToolTip";
|
import { ToolTip } from "components/ToolTip";
|
||||||
import { AppStaticProps, getAppStaticProps } from "graphql/getAppStaticProps";
|
import { AppStaticProps, getAppStaticProps } from "graphql/getAppStaticProps";
|
||||||
import { getReadySdk } from "graphql/sdk";
|
import { getReadySdk } from "graphql/sdk";
|
||||||
|
import { getNextContent, getPreviousContent } from "helpers/contents";
|
||||||
import {
|
import {
|
||||||
prettyinlineTitle,
|
prettyinlineTitle,
|
||||||
prettyLanguage,
|
prettyLanguage,
|
||||||
@ -34,48 +35,6 @@ interface Props extends AppStaticProps {
|
|||||||
content: ContentWithTranslations;
|
content: ContentWithTranslations;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPreviousContent(
|
|
||||||
group: Immutable<
|
|
||||||
NonNullable<
|
|
||||||
NonNullable<
|
|
||||||
NonNullable<
|
|
||||||
NonNullable<ContentWithTranslations["group"]>["data"]
|
|
||||||
>["attributes"]
|
|
||||||
>["contents"]
|
|
||||||
>["data"]
|
|
||||||
>,
|
|
||||||
currentSlug: string
|
|
||||||
) {
|
|
||||||
for (let index = 0; index < group.length; index += 1) {
|
|
||||||
const content = group[index];
|
|
||||||
if (content.attributes?.slug === currentSlug && index > 0) {
|
|
||||||
return group[index - 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNextContent(
|
|
||||||
group: Immutable<
|
|
||||||
NonNullable<
|
|
||||||
NonNullable<
|
|
||||||
NonNullable<
|
|
||||||
NonNullable<ContentWithTranslations["group"]>["data"]
|
|
||||||
>["attributes"]
|
|
||||||
>["contents"]
|
|
||||||
>["data"]
|
|
||||||
>,
|
|
||||||
currentSlug: string
|
|
||||||
) {
|
|
||||||
for (let index = 0; index < group.length; index += 1) {
|
|
||||||
const content = group[index];
|
|
||||||
if (content.attributes?.slug === currentSlug && index < group.length - 1) {
|
|
||||||
return group[index + 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Content(props: Immutable<Props>): JSX.Element {
|
export default function Content(props: Immutable<Props>): JSX.Element {
|
||||||
const { langui, content, languages } = props;
|
const { langui, content, languages } = props;
|
||||||
const isMobile = useMediaMobile();
|
const isMobile = useMediaMobile();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user