Skip to content

Commit

Permalink
Add common IIIF share component.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewjordan committed Oct 11, 2024
1 parent 2f69b1d commit 305d8c5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions components/Shared/IIIF/Share.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const IIIFShare = ({ uri }) => {
return <>resource: {uri}</>;
};

export default IIIFShare;
2 changes: 2 additions & 0 deletions components/Work/TopInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Button } from "@nulib/design-system";
import Card from "@/components/Shared/Card";
import { DefinitionListWrapper } from "@/components/Shared/DefinitionList.styled";
import Expand from "@/components/Shared/Expand/Expand";
import IIIFShare from "../Shared/IIIF/Share";
import { Manifest } from "@iiif/presentation-3";
import type { Work } from "@nulib/dcapi-types";
import WorkActionsDialog from "@/components/Work/ActionsDialog/ActionsDialog";
Expand Down Expand Up @@ -72,6 +73,7 @@ const WorkTopInfo: React.FC<TopInfoProps> = ({
<TopInfoWrapper>
<header>
<Label label={manifest.label} as="h1" data-testid="title" />
<IIIFShare uri={manifest.id} />
{manifest?.summary && (
<Summary summary={manifest.summary} as="p" data-testid="summary" />
)}
Expand Down
13 changes: 13 additions & 0 deletions lib/dc-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import axios, { AxiosError, RawAxiosRequestHeaders } from "axios";

import type { ApiSearchRequestBody } from "@/types/api/request";
import { DC_API_SEARCH_URL } from "./constants/endpoints";
import { NextRouter } from "next/router";

interface ApiGetRequestParams {
url: string;
Expand Down Expand Up @@ -72,6 +74,16 @@ async function getIIIFResource<R>(
}
}

function iiifSearchUrl(query: NextRouter["query"], size?: number): string {
const url = new URL(DC_API_SEARCH_URL);
Object.keys(query).forEach((key) => {
url.searchParams.append(key, query[key] as string);
});
if (size) url.searchParams.append("size", size.toString());
url.searchParams.append("as", "iiif");
return url.toString();
}

function handleError(err: unknown) {
const error = err as AxiosError;
if (error.response) {
Expand All @@ -96,4 +108,5 @@ export {
apiPostRequest,
getIIIFResource,
handleError,
iiifSearchUrl,
};
2 changes: 2 additions & 0 deletions pages/collections/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Container from "@/components/Shared/Container";
import Facts from "@/components/Shared/Facts";
import Head from "next/head";
import Hero from "@/components/Hero/Hero";
import IIIFShare from "@/components/Shared/IIIF/Share";
import Layout from "components/layout";
import ReadMore from "@/components/Shared/ReadMore";
import { buildDataLayer } from "@/lib/ga/data-layer";
Expand Down Expand Up @@ -172,6 +173,7 @@ const Collection: NextPage = () => {
</Facts>
</Container>
</Interstitial>
<IIIFShare />
<Container>
<Tabs defaultValue="explore">
<TabsList aria-label="Explore">
Expand Down

0 comments on commit 305d8c5

Please sign in to comment.