import AppLayout from "components/AppLayout"; import Chip from "components/Chip"; import Img from "components/Img"; import Button from "components/Inputs/Button"; import Switch from "components/Inputs/Switch"; import InsetBox from "components/InsetBox"; import ContentLine from "components/Library/ContentLine"; import LightBox from "components/LightBox"; import NavOption from "components/PanelComponents/NavOption"; import ReturnButton, { ReturnButtonType, } from "components/PanelComponents/ReturnButton"; import ContentPanel, { ContentPanelWidthSizes, } from "components/Panels/ContentPanel"; import SubPanel from "components/Panels/SubPanel"; import ThumbnailPreview from "components/PreviewCard"; import { useAppLayout } from "contexts/AppLayoutContext"; import { Enum_Componentmetadatabooks_Binding_Type, Enum_Componentmetadatabooks_Page_Order, GetLibraryItemQuery, } from "graphql/generated"; import { getReadySdk } from "graphql/sdk"; import { prettyDate, prettyinlineTitle, prettyItemSubType, prettyItemType, prettyPrice, prettyURL, } from "helpers/formatters"; import { AppStaticProps, getAppStaticProps } from "helpers/getAppStaticProps"; import { sortContent } from "helpers/others"; import { getAssetURL, ImageQuality } from "helpers/img"; import { convertMmToInch } from "helpers/numbers"; import { GetStaticPathsContext, GetStaticPathsResult, GetStaticPropsContext, } from "next"; import { useState } from "react"; interface Props extends AppStaticProps { item: Exclude< GetLibraryItemQuery["libraryItems"], null | undefined >["data"][number]["attributes"]; itemId: Exclude< GetLibraryItemQuery["libraryItems"], null | undefined >["data"][number]["id"]; } export default function LibrarySlug(props: Props): JSX.Element { const { item, langui, currencies } = props; const appLayout = useAppLayout(); const isVariantSet = item?.metadata?.[0]?.__typename === "ComponentMetadataGroup" && item.metadata[0].subtype?.data?.attributes?.slug === "variant-set"; sortContent(item?.contents); const [lightboxOpen, setLightboxOpen] = useState(false); const [lightboxImages, setLightboxImages] = useState([""]); const [lightboxIndex, setLightboxIndex] = useState(0); const [keepInfoVisible, setKeepInfoVisible] = useState(false); let displayOpenScans = false; if (item?.contents?.data) for (const content of item.contents.data) { if ( content.attributes?.scan_set && content.attributes.scan_set.length > 0 ) displayOpenScans = true; } const subPanel = (
appLayout.setSubPanelOpen(false)} /> {item?.gallery && item.gallery.data.length > 0 && ( appLayout.setSubPanelOpen(false)} /> )} appLayout.setSubPanelOpen(false)} /> {item?.subitems && item.subitems.data.length > 0 && ( appLayout.setSubPanelOpen(false)} /> )} {item?.contents && item.contents.data.length > 0 && ( appLayout.setSubPanelOpen(false)} /> )}
); const contentPanel = (
{ if (item?.thumbnail?.data?.attributes) { setLightboxOpen(true); setLightboxImages([ getAssetURL( item.thumbnail.data.attributes.url, ImageQuality.Large ), ]); setLightboxIndex(0); } }} > {item?.thumbnail?.data?.attributes ? ( ) : (
)}
{item?.subitem_of?.data[0]?.attributes && (

{langui.subitem_of}

)}

{item?.title}

{item?.subtitle &&

{item.subtitle}

}
{item?.descriptions?.[0] && (

{item.descriptions[0].description}

)} {!( item?.metadata && item.metadata[0]?.__typename === "ComponentMetadataGroup" && (item.metadata[0].subtype?.data?.attributes?.slug === "variant-set" || item.metadata[0].subtype?.data?.attributes?.slug === "relation-set") ) && ( <> {item?.urls && item.urls.length ? (

Available at

{item.urls.map((url) => ( <> {url?.url && ( )} ))}
) : (

This item is not for sale or is no longer available

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

{langui.details}

{item?.metadata?.[0] && (

{langui.type}

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

{langui.release_date}

{prettyDate(item.release_date)}

)} {item?.price && (

{langui.price}

{prettyPrice( item.price, currencies, item.price.currency?.data?.attributes?.code )}

{item.price.currency?.data?.attributes?.code !== appLayout.currency && (

{prettyPrice(item.price, currencies, appLayout.currency)}{" "}
({langui.calculated?.toLowerCase()})

)}
)}
{item?.categories && item.categories.data.length > 0 && (

{langui.categories}

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

{langui.size}

{langui.width}:

{item.size.width} mm

{convertMmToInch(item.size.width)} in

{langui.height}:

{item.size.height} mm

{convertMmToInch(item.size.height)} in

{item.size.thickness && (

{langui.thickness}:

{item.size.thickness} mm

{convertMmToInch(item.size.thickness)} in

)}
)} {item?.metadata?.[0]?.__typename !== "ComponentMetadataGroup" && item?.metadata?.[0]?.__typename !== "ComponentMetadataOther" && ( <>

{langui.type_information}

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

{langui.pages}:

{item.metadata[0].page_count}

{langui.binding}:

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

{langui.page_order}:

{item.metadata[0].page_order === Enum_Componentmetadatabooks_Page_Order.LeftToRight ? langui.left_to_right : langui.right_to_left}

{langui.languages}:

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

{lang.attributes?.name}

))}
)}
)}
{item?.subitems && item.subitems.data.length > 0 && (

{isVariantSet ? langui.variants : langui.subitems}

{"Always show info"}:

{item.subitems.data.map((subitem) => ( <> {subitem.attributes && ( 0 && subitem.attributes.metadata[0] ? [prettyItemSubType(subitem.attributes.metadata[0])] : [] } bottomChips={subitem.attributes.categories?.data.map( (category) => category.attributes?.short ?? "" )} metadata={{ currencies: currencies, release_date: subitem.attributes.release_date, price: subitem.attributes.price, position: "Bottom", }} /> )} ))}
)} {item?.contents && item.contents.data.length > 0 && (

{langui.contents}

{displayOpenScans && ( )}
{item.contents.data.map((content) => ( ))}
)}
); return ( ); } export async function getStaticProps( context: GetStaticPropsContext ): Promise<{ notFound: boolean } | { props: Props }> { const sdk = getReadySdk(); const item = await sdk.getLibraryItem({ slug: context.params?.slug ? context.params.slug.toString() : "", language_code: context.locale ?? "en", }); if (!item.libraryItems?.data[0]?.attributes) return { notFound: true }; const props: Props = { ...(await getAppStaticProps(context)), item: item.libraryItems.data[0].attributes, itemId: item.libraryItems.data[0].id, }; return { props: props, }; } export async function getStaticPaths( context: GetStaticPathsContext ): Promise { const sdk = getReadySdk(); const libraryItems = await sdk.getLibraryItemsSlugs(); const paths: GetStaticPathsResult["paths"] = []; if (libraryItems.libraryItems) { libraryItems.libraryItems.data.map((item) => { context.locales?.map((local) => { paths.push({ params: { slug: item.attributes?.slug }, locale: local }); }); }); } return { paths, fallback: "blocking", }; }