From 1a9f5ae41b461a127864dc53f349cd6c1263d1ce Mon Sep 17 00:00:00 2001 From: DrMint Date: Fri, 11 Mar 2022 00:32:36 +0100 Subject: [PATCH] Display library item's categories on its page --- .../Library/LibraryItemsPreview.tsx | 49 +++++++++---------- src/graphql/operation.graphql | 18 +++++++ src/graphql/operations-types.ts | 24 +++++++++ src/pages/library/[slug].tsx | 14 ++++++ 4 files changed, 80 insertions(+), 25 deletions(-) diff --git a/src/components/Library/LibraryItemsPreview.tsx b/src/components/Library/LibraryItemsPreview.tsx index 392a3fc..85afd83 100644 --- a/src/components/Library/LibraryItemsPreview.tsx +++ b/src/components/Library/LibraryItemsPreview.tsx @@ -63,31 +63,30 @@ export default function LibraryItemsPreview( ))} - {item.release_date || - (item.price && ( -
- {item.release_date && ( -

- - event - - {prettyDate(item.release_date)} -

- )} - {item.price && props.currencies && ( -

- - shopping_cart - - {prettyPrice( - item.price, - props.currencies, - appLayout.currency - )} -

- )} -
- ))} + {(item.release_date || item.price) && ( +
+ {item.release_date && ( +

+ + event + + {prettyDate(item.release_date)} +

+ )} + {item.price && props.currencies && ( +

+ + shopping_cart + + {prettyPrice( + item.price, + props.currencies, + appLayout.currency + )} +

+ )} +
+ )} diff --git a/src/graphql/operation.graphql b/src/graphql/operation.graphql index 5ec508c..0d7a7be 100644 --- a/src/graphql/operation.graphql +++ b/src/graphql/operation.graphql @@ -363,6 +363,15 @@ query getLibraryItem($slug: String, $language_code: String) { } } } + categories { + data { + id + attributes { + name + short + } + } + } size { width height @@ -532,6 +541,15 @@ query getLibraryItem($slug: String, $language_code: String) { } } } + categories { + data { + id + attributes { + name + short + } + } + } metadata { __typename ... on ComponentMetadataBooks { diff --git a/src/graphql/operations-types.ts b/src/graphql/operations-types.ts index c9d8ee3..7735c06 100644 --- a/src/graphql/operations-types.ts +++ b/src/graphql/operations-types.ts @@ -522,6 +522,18 @@ export type GetLibraryItemQuery = { }; }; }; + categories: { + __typename: "CategoryRelationResponseCollection"; + data: Array<{ + __typename: "CategoryEntity"; + id: string; + attributes: { + __typename: "Category"; + name: string; + short: string; + }; + }>; + }; size: { __typename: "ComponentBasicsSize"; width: number; @@ -738,6 +750,18 @@ export type GetLibraryItemQuery = { }; }; }; + categories: { + __typename: "CategoryRelationResponseCollection"; + data: Array<{ + __typename: "CategoryEntity"; + id: string; + attributes: { + __typename: "Category"; + name: string; + short: string; + }; + }>; + }; metadata: Array< | { __typename: "ComponentMetadataAudio"; diff --git a/src/pages/library/[slug].tsx b/src/pages/library/[slug].tsx index f4fdba3..d37c98a 100644 --- a/src/pages/library/[slug].tsx +++ b/src/pages/library/[slug].tsx @@ -216,6 +216,20 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element { )} + + {item.categories.data.length > 0 && ( +
+

{langui.categories}

+
+ {item.categories.data.map((category) => ( + + {category.attributes.short} + + ))} +
+
+ )} + {item.size && ( <>

{langui.size}