From 676b73318e378a84784adbf927d2a78a82a16d74 Mon Sep 17 00:00:00 2001 From: DrMint Date: Tue, 8 Feb 2022 05:52:22 +0100 Subject: [PATCH] Added more info on library items --- .../Library/LibraryItemComponent.tsx | 29 ++- src/graphql/operation.graphql | 2 +- src/pages/library/[slug].tsx | 213 +++++++++++------- src/pages/library/index.tsx | 2 +- src/queries/helpers.ts | 20 +- 5 files changed, 167 insertions(+), 99 deletions(-) diff --git a/src/components/Library/LibraryItemComponent.tsx b/src/components/Library/LibraryItemComponent.tsx index fdafa8c..df51c63 100644 --- a/src/components/Library/LibraryItemComponent.tsx +++ b/src/components/Library/LibraryItemComponent.tsx @@ -10,47 +10,44 @@ export type LibraryItemComponentProps = { export default function LibraryItemComponent( props: LibraryItemComponentProps ): JSX.Element { + const item = props.item.attributes; return ( - +
- {props.item.attributes.thumbnail.data ? ( + {item.thumbnail.data ? ( { ) : (
)}
-

{props.item.attributes.title}

-

{props.item.attributes.subtitle}

+

{item.title}

+

{item.subtitle}

- {props.item.attributes.price ? ( + {item.price ? (

event - {prettyDate(props.item.attributes.release_date)} + {prettyDate(item.release_date)}

) : ( "" )} - {props.item.attributes.price ? ( + {item.price ? (

shopping_cart - {prettyPrice(props.item.attributes.price)} + {prettyPrice(item.price)}

) : ( "" diff --git a/src/graphql/operation.graphql b/src/graphql/operation.graphql index fe23367..30d6374 100644 --- a/src/graphql/operation.graphql +++ b/src/graphql/operation.graphql @@ -53,7 +53,7 @@ query getLibraryItemsPreview($language_code: String) { libraryItems( filters: { root_item: { eq: true } } pagination: { limit: -1 } - sort: ["slug:asc"] + sort: ["title:asc","subtitle:asc"] ) { data { id diff --git a/src/pages/library/[slug].tsx b/src/pages/library/[slug].tsx index d18d090..e6bf5d2 100644 --- a/src/pages/library/[slug].tsx +++ b/src/pages/library/[slug].tsx @@ -2,12 +2,12 @@ import ContentPanel, { ContentPanelWidthSizes, } from "components/Panels/ContentPanel"; import Image from "next/image"; -import Link from "next/link"; import { GetStaticPaths, GetStaticProps } from "next"; import { applyCustomAppProps } from "pages/_app"; import { getLibraryItem, getLibraryItemsSlugs } from "graphql/operations"; import { GetLibraryItemQuery } from "graphql/operations-types"; import { + capitalizeString, convertMmToInch, getAssetURL, prettyDate, @@ -32,9 +32,9 @@ applyCustomAppProps(Library, { }); export default function Library(props: Props): JSX.Element { - const libraryItem = props.libraryItem.libraryItems.data[0]; + const item = props.libraryItem.libraryItems.data[0].attributes; - libraryItem.attributes.contents.data.sort((a, b) => { + item.contents.data.sort((a, b) => { if ( a.attributes.range[0].__typename === "ComponentRangePageRange" && b.attributes.range[0].__typename === "ComponentRangePageRange" @@ -55,7 +55,7 @@ export default function Library(props: Props): JSX.Element { - {libraryItem.attributes.gallery.data.length > 0 ? ( + {item.gallery.data.length > 0 ? ( ) : ( "" @@ -63,13 +63,13 @@ export default function Library(props: Props): JSX.Element { - {libraryItem.attributes.subitems.data.length > 0 ? ( + {item.subitems.data.length > 0 ? ( ) : ( "" )} - {libraryItem.attributes.contents.data.length > 0 ? ( + {item.contents.data.length > 0 ? ( ) : ( "" @@ -79,17 +79,12 @@ export default function Library(props: Props): JSX.Element {
- {libraryItem.attributes.thumbnail.data ? ( + {item.thumbnail.data ? ( { ) : (
@@ -100,17 +95,16 @@ export default function Library(props: Props): JSX.Element { id="summary" className="bg-mid w-full grid place-items-center p-8 rounded-2xl" > -
- {libraryItem.attributes.subitem_of.data.length > 0 ? ( +
+ {item.subitem_of.data.length > 0 ? (

Subitem of

@@ -118,28 +112,26 @@ export default function Library(props: Props): JSX.Element { "" )}
-

{libraryItem.attributes.title}

- {libraryItem.attributes.subtitle ? ( -

- {libraryItem.attributes.subtitle} -

+

{item.title}

+ {item.subtitle ? ( +

{item.subtitle}

) : ( "" )}
- {libraryItem.attributes.descriptions.length > 0 ? ( -

{libraryItem.attributes.descriptions[0].description}

+ {item.descriptions.length > 0 ? ( +

{item.descriptions[0].description}

) : ( "" )}
- {libraryItem.attributes.gallery.data.length > 0 ? ( + {item.gallery.data.length > 0 ? (