import ContentPanel, { ContentPanelWidthSizes, } from "components/Panels/ContentPanel"; import { GetStaticPaths, GetStaticProps } from "next"; import { getLibraryItem, getLibraryItemsSlugs, getWebsiteInterface, } from "graphql/operations"; import { Enum_Componentmetadatabooks_Binding_Type, Enum_Componentmetadatabooks_Page_Order, GetLibraryItemQuery, GetWebsiteInterfaceQuery, } from "graphql/operations-types"; import { convertMmToInch, prettyDate, prettyinlineTitle, prettyItemType, prettyItemSubType, prettyPrice, prettySlug, prettyTestError, prettyTestWarning, sortContent, } from "queries/helpers"; import SubPanel from "components/Panels/SubPanel"; import ReturnButton from "components/PanelComponents/ReturnButton"; import NavOption from "components/PanelComponents/NavOption"; import Chip from "components/Chip"; import Button from "components/Button"; import HorizontalLine from "components/HorizontalLine"; import AppLayout from "components/AppLayout"; import LibraryItemsPreview from "components/Library/LibraryItemsPreview"; import InsetBox from "components/InsetBox"; import Img, { ImageQuality } from "components/Img"; import { useAppLayout } from "contexts/AppLayoutContext"; import { useRouter } from "next/router"; interface LibrarySlugProps { libraryItem: GetLibraryItemQuery; langui: GetWebsiteInterfaceQuery; } export default function LibrarySlug(props: LibrarySlugProps): JSX.Element { useTesting(props); const item = props.libraryItem.libraryItems.data[0].attributes; const langui = props.langui.websiteInterfaces.data[0].attributes; const appLayout = useAppLayout(); const isVariantSet = item.metadata.length > 0 && item.metadata[0].__typename === "ComponentMetadataOther" && item.metadata[0].subtype.data.attributes.slug === "variant-set"; sortContent(item.contents); const subPanel = (
appLayout.setSubPanelOpen(false)} /> {item.gallery.data.length > 0 ? ( appLayout.setSubPanelOpen(false)} /> ) : ( "" )} appLayout.setSubPanelOpen(false)} /> {item.subitems.data.length > 0 ? ( appLayout.setSubPanelOpen(false)} /> ) : ( "" )} {item.contents.data.length > 0 ? ( ) : ( "" )}
); const contentPanel = (
{item.thumbnail.data ? ( ) : (
)}
{item.subitem_of.data.length > 0 ? (

{langui.global_subitem_of}

) : ( "" )}

{item.title}

{item.subtitle ? (

{item.subtitle}

) : ( "" )}
{item.descriptions.length > 0 ? (

{item.descriptions[0].description}

) : ( "" )}
{item.gallery.data.length > 0 ? ( ) : ( "" )}

{langui.library_item_details}

{item.metadata.length > 0 ? (

{langui.global_type}

{prettyItemType(item.metadata[0], langui)} {"›"} {prettyItemSubType(item.metadata[0])}
) : ( "" )} {item.release_date ? (

{langui.global_release_date}

{prettyDate(item.release_date)}

) : ( "" )} {item.price ? (

{langui.global_price}

{prettyPrice(item.price)}

) : ( "" )}
{item.size ? ( <>

{langui.library_item_physical_size}

{langui.global_width}:

{item.size.width} mm

{convertMmToInch(item.size.width)} in

{langui.global_height}:

{item.size.height} mm

{convertMmToInch(item.size.height)} in

{item.size.thickness ? (

{langui.global_thickness}:

{item.size.thickness} mm

{convertMmToInch(item.size.thickness)} in

) : ( "" )}
) : ( "" )} {item.metadata.length > 0 ? ( <>

{langui.library_item_type_information}

{item.metadata[0].__typename === "ComponentMetadataBooks" ? ( <>

{langui.global_pages}:

{item.metadata[0].page_count}

{langui.global_binding}:

{item.metadata[0].binding_type === Enum_Componentmetadatabooks_Binding_Type.Paperback ? langui.global_paperback : item.metadata[0].binding_type === Enum_Componentmetadatabooks_Binding_Type.Hardcover ? langui.global_hardcover : ""}

{langui.global_page_order}:

{item.metadata[0].page_order === Enum_Componentmetadatabooks_Page_Order.LeftToRight ? langui.global_left_to_right : item.metadata[0].page_order === Enum_Componentmetadatabooks_Page_Order.RightToLeft ? langui.global_right_to_left : ""}

{langui.global_languages}:

{item.metadata[0].languages.data.map((lang) => (

{lang.attributes.name}

))}
) : item.metadata[0].__typename === "ComponentMetadataAudio" ? ( <> ) : item.metadata[0].__typename === "ComponentMetadataVideo" ? ( <> ) : item.metadata[0].__typename === "ComponentMetadataGame" ? ( <> ) : item.metadata[0].__typename === "ComponentMetadataOther" ? ( <>

{langui.global_type}:

{item.metadata[0].subtype.data.attributes.titles .length > 0 ? item.metadata[0].subtype.data.attributes.titles[0] .title : prettySlug( item.metadata[0].subtype.data.attributes.slug )}
) : ( "" )}
) : ( "" )}
{item.subitems.data.length > 0 ? (

{isVariantSet ? langui.library_item_variants : langui.library_item_subitems}

{item.subitems.data.map((subitem) => ( ))}
) : ( "" )} {item.contents.data.length > 0 ? (

{langui.library_item_content}

{item.contents.data.map((content) => (

{content.attributes.content.data && content.attributes.content.data.attributes.titles .length > 0 ? prettyinlineTitle( content.attributes.content.data.attributes .titles[0].pre_title, content.attributes.content.data.attributes .titles[0].title, content.attributes.content.data.attributes .titles[0].subtitle ) : prettySlug(content.attributes.slug, item.slug)}

{content.attributes.content.data?.attributes.categories.data.map( (category) => ( {category.attributes.short} ) )}

{content.attributes.range[0].__typename === "ComponentRangePageRange" ? content.attributes.range[0].starting_page : ""}

{content.attributes.content.data ? ( {content.attributes.content.data.attributes.type.data .attributes.titles.length > 0 ? content.attributes.content.data.attributes.type.data .attributes.titles[0].title : prettySlug( content.attributes.content.data.attributes.type .data.attributes.slug )} ) : ( "" )}
subdirectory_arrow_right {content.attributes.scan_set.length > 0 ? ( ) : ( "" )} {content.attributes.content.data ? ( ) : ( "" )} {content.attributes.scan_set.length === 0 && !content.attributes.content.data ? "The content is not available" : ""}
))}
) : ( "" )}
); return ( 0 ? item.descriptions[0].description : undefined } /> ); } export const getStaticProps: GetStaticProps = async (context) => { if (context.params) { if (context.params.slug && context.locale) { if (context.params.slug instanceof Array) context.params.slug = context.params.slug.join(""); const props: LibrarySlugProps = { libraryItem: await getLibraryItem({ slug: context.params.slug, language_code: context.locale, }), langui: await getWebsiteInterface({ language_code: context.locale, }), }; return { props: props, }; } } return { props: {} }; }; export const getStaticPaths: GetStaticPaths = async (context) => { type Path = { params: { slug: string; }; locale: string; }; const data = await getLibraryItemsSlugs({}); const paths: Path[] = []; data.libraryItems.data.map((item) => { context.locales?.map((local) => { paths.push({ params: { slug: item.attributes.slug }, locale: local }); }); }); return { paths, fallback: false, }; }; function useTesting(props: LibrarySlugProps) { const libraryItem = props.libraryItem.libraryItems.data[0].attributes; const router = useRouter(); const libraryItemURL = "/admin/content-manager/collectionType/api::library-item.library-item/" + props.libraryItem.libraryItems.data[0].id; sortContent(libraryItem.contents); if (router.locale === "en") { if (!libraryItem.thumbnail.data) { prettyTestError( router, "Missing thumbnail", ["libraryItem"], libraryItemURL ); } if (libraryItem.metadata.length === 0) { prettyTestError( router, "Missing metadata", ["libraryItem"], libraryItemURL ); } else { if ( libraryItem.metadata[0].__typename === "ComponentMetadataOther" && (libraryItem.metadata[0].subtype.data.attributes.slug === "relation-set" || libraryItem.metadata[0].subtype.data.attributes.slug === "variant-set") ) { // This is a group type item if (libraryItem.price) { prettyTestError( router, "Group-type items shouldn't have price", ["libraryItem"], libraryItemURL ); } if (libraryItem.size) { prettyTestError( router, "Group-type items shouldn't have size", ["libraryItem"], libraryItemURL ); } if (libraryItem.release_date) { prettyTestError( router, "Group-type items shouldn't have release_date", ["libraryItem"], libraryItemURL ); } if (libraryItem.contents.data.length > 0) { prettyTestError( router, "Group-type items shouldn't have contents", ["libraryItem"], libraryItemURL ); } if (libraryItem.subitems.data.length === 0) { prettyTestError( router, "Group-type items should have subitems", ["libraryItem"], libraryItemURL ); } } else { // This is a normal item if (libraryItem.metadata[0].__typename === "ComponentMetadataOther") { if ( libraryItem.metadata[0].subtype.data.attributes.slug === "audio-case" ) { let hasAudioSubItem = false; libraryItem.subitems.data.map((subitem) => { if ( subitem.attributes.metadata.length > 0 && subitem.attributes.metadata[0].__typename === "ComponentMetadataAudio" ) hasAudioSubItem = true; }); if (!hasAudioSubItem) { prettyTestError( router, "Audio-case item doesn't have an audio-typed subitem", ["libraryItem"], libraryItemURL ); } } else if ( libraryItem.metadata[0].subtype.data.attributes.slug === "game-case" ) { let hasGameSubItem = false; libraryItem.subitems.data.map((subitem) => { if ( subitem.attributes.metadata.length > 0 && subitem.attributes.metadata[0].__typename === "ComponentMetadataGame" ) hasGameSubItem = true; }); if (!hasGameSubItem) { prettyTestError( router, "Game-case item doesn't have an Game-typed subitem", ["libraryItem"], libraryItemURL ); } } else if ( libraryItem.metadata[0].subtype.data.attributes.slug === "video-case" ) { let hasVideoSubItem = false; libraryItem.subitems.data.map((subitem) => { if ( subitem.attributes.metadata.length > 0 && subitem.attributes.metadata[0].__typename === "ComponentMetadataVideo" ) hasVideoSubItem = true; }); if (!hasVideoSubItem) { prettyTestError( router, "Video-case item doesn't have an Video-typed subitem", ["libraryItem"], libraryItemURL ); } } else if ( libraryItem.metadata[0].subtype.data.attributes.slug === "item-set" ) { if (libraryItem.subitems.data.length === 0) { prettyTestError( router, "Item-set item should have subitems", ["libraryItem"], libraryItemURL ); } } } if (!libraryItem.price) { prettyTestWarning( router, "Missing price", ["libraryItem"], libraryItemURL ); } else { if (!libraryItem.price.amount) { prettyTestError( router, "Missing amount", ["libraryItem", "price"], libraryItemURL ); } if (!libraryItem.price.currency) { prettyTestError( router, "Missing currency", ["libraryItem", "price"], libraryItemURL ); } } if (!libraryItem.digital) { if (!libraryItem.size) { prettyTestWarning( router, "Missing size", ["libraryItem"], libraryItemURL ); } else { if (!libraryItem.size.width) { prettyTestWarning( router, "Missing width", ["libraryItem", "size"], libraryItemURL ); } if (!libraryItem.size.height) { prettyTestWarning( router, "Missing height", ["libraryItem", "size"], libraryItemURL ); } if (!libraryItem.size.thickness) { prettyTestWarning( router, "Missing thickness", ["libraryItem", "size"], libraryItemURL ); } } } if (!libraryItem.release_date) { prettyTestWarning( router, "Missing release_date", ["libraryItem"], libraryItemURL ); } else { if (!libraryItem.release_date.year) { prettyTestError( router, "Missing year", ["libraryItem", "release_date"], libraryItemURL ); } if (!libraryItem.release_date.month) { prettyTestError( router, "Missing month", ["libraryItem", "release_date"], libraryItemURL ); } if (!libraryItem.release_date.day) { prettyTestError( router, "Missing day", ["libraryItem", "release_date"], libraryItemURL ); } } if (libraryItem.contents.data.length === 0) { prettyTestWarning( router, "Missing contents", ["libraryItem"], libraryItemURL ); } else { let currentRangePage = 0; libraryItem.contents.data.map((content) => { const contentURL = "/admin/content-manager/collectionType/api::content.content/" + content.id; if (content.attributes.scan_set.length === 0) { prettyTestWarning( router, "Missing scan_set", ["libraryItem", "content", content.id], contentURL ); } if (content.attributes.range.length === 0) { prettyTestWarning( router, "Missing range", ["libraryItem", "content", content.id], contentURL ); } else if ( content.attributes.range[0].__typename === "ComponentRangePageRange" ) { if ( content.attributes.range[0].starting_page < currentRangePage + 1 ) { prettyTestError( router, `Overlapping pages ${content.attributes.range[0].starting_page} to ${currentRangePage}`, ["libraryItem", "content", content.id, "range"], libraryItemURL ); } else if ( content.attributes.range[0].starting_page > currentRangePage + 1 ) { prettyTestError( router, `Missing pages ${currentRangePage + 1} to ${ content.attributes.range[0].starting_page - 1 }`, ["libraryItem", "content", content.id, "range"], libraryItemURL ); } if (!content.attributes.content.data) { prettyTestWarning( router, "Missing content", ["libraryItem", "content", content.id, "range"], libraryItemURL ); } currentRangePage = content.attributes.range[0].ending_page; } }); if (libraryItem.metadata[0].__typename === "ComponentMetadataBooks") { if (currentRangePage < libraryItem.metadata[0].page_count) { prettyTestError( router, `Missing pages ${currentRangePage + 1} to ${ libraryItem.metadata[0].page_count }`, ["libraryItem", "content"], libraryItemURL ); } else if (currentRangePage > libraryItem.metadata[0].page_count) { prettyTestError( router, `Page overflow, content references pages up to ${currentRangePage} when the highest expected was ${libraryItem.metadata[0].page_count}`, ["libraryItem", "content"], libraryItemURL ); } if (libraryItem.metadata[0].languages.data.length === 0) { prettyTestWarning( router, "Missing language", ["libraryItem", "metadata"], libraryItemURL ); } if (!libraryItem.metadata[0].page_count) { prettyTestWarning( router, "Missing page_count", ["libraryItem", "metadata"], libraryItemURL ); } } } } } if (!libraryItem.root_item && libraryItem.subitem_of.data.length === 0) { prettyTestError( router, "This item is inaccessible (not root item and not subitem of another item)", ["libraryItem"], libraryItemURL ); } if (libraryItem.gallery.data.length === 0) { prettyTestWarning( router, "Missing gallery", ["libraryItem"], libraryItemURL ); } } if (libraryItem.descriptions.length === 0) { prettyTestWarning( router, "Missing description", ["libraryItem"], libraryItemURL ); } }