|
| 1 | +import { |
| 2 | + ActionsDialogStyled, |
| 3 | + Content, |
| 4 | +} from "@/components/Work/ActionsDialog/ActionsDialog.styled"; |
| 5 | +import React, { useEffect, useState } from "react"; |
| 6 | + |
| 7 | +import ActionsDialogAside from "@/components/Work/ActionsDialog/Aside"; |
| 8 | +import { Canvas } from "@iiif/presentation-3"; |
| 9 | +import EmbedImages from "./EmbedImages"; |
| 10 | +import EmbedViewer from "@/components/Work/ActionsDialog/DownloadAndShare/EmbedViewer"; |
| 11 | +import IIIFManifest from "./IIIFManifest"; |
| 12 | +import SharedSocial from "@/components/Shared/Social"; |
| 13 | +import { getAnnotationBodyType } from "@/lib/iiif/manifest-helpers"; |
| 14 | +import { useRouter } from "next/router"; |
| 15 | +import useWorkAuth from "@/hooks/useWorkAuth"; |
| 16 | +import { useWorkState } from "@/context/work-context"; |
| 17 | + |
| 18 | +export const embedWarningMessage = |
| 19 | + "Embed is not available for works restricted to the Northwestern University community"; |
| 20 | + |
| 21 | +const DownloadAndShare: React.FC = () => { |
| 22 | + const { workState } = useWorkState(); |
| 23 | + const { manifest, work } = workState; |
| 24 | + const [imageCanvases, setImageCanvases] = useState<Canvas[]>([]); |
| 25 | + const router = useRouter(); |
| 26 | + const isSharedLinkPage = router.pathname.includes("/shared"); |
| 27 | + const { isUserLoggedIn, isWorkInstitution, isWorkRestricted } = |
| 28 | + useWorkAuth(work); |
| 29 | + |
| 30 | + const showEmbedWarning = Boolean( |
| 31 | + isWorkRestricted || (isUserLoggedIn && isWorkInstitution) |
| 32 | + ); |
| 33 | + |
| 34 | + useEffect(() => { |
| 35 | + if (manifest?.items && Array.isArray(manifest?.items)) { |
| 36 | + const imageCanvases = manifest.items.filter( |
| 37 | + (item) => getAnnotationBodyType(item) === "Image" |
| 38 | + ); |
| 39 | + setImageCanvases(imageCanvases); |
| 40 | + } |
| 41 | + }, [manifest]); |
| 42 | + |
| 43 | + if (!manifest || !work) return <></>; |
| 44 | + |
| 45 | + return ( |
| 46 | + <ActionsDialogStyled> |
| 47 | + <ActionsDialogAside> |
| 48 | + {work.title && work.thumbnail && ( |
| 49 | + <SharedSocial |
| 50 | + title={work.title} |
| 51 | + media={work.thumbnail} |
| 52 | + description={work.description} |
| 53 | + /> |
| 54 | + )} |
| 55 | + </ActionsDialogAside> |
| 56 | + <Content> |
| 57 | + {!isSharedLinkPage && <IIIFManifest manifest={manifest} work={work} />} |
| 58 | + |
| 59 | + <EmbedViewer |
| 60 | + manifestId={work.iiif_manifest} |
| 61 | + showEmbedWarning={showEmbedWarning} |
| 62 | + work={work} |
| 63 | + /> |
| 64 | + |
| 65 | + {imageCanvases.length > 0 && ( |
| 66 | + <EmbedImages |
| 67 | + manifest={manifest} |
| 68 | + showEmbedWarning={showEmbedWarning} |
| 69 | + work={work} |
| 70 | + /> |
| 71 | + )} |
| 72 | + </Content> |
| 73 | + </ActionsDialogStyled> |
| 74 | + ); |
| 75 | +}; |
| 76 | + |
| 77 | +export default DownloadAndShare; |
0 commit comments