-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from danskernesdigitalebibliotek/DDFBRA-200-an…
…onym-og-indlogget-bruger-kan-prove-e-bog Ddfbra 200 anonym og indlogget bruger kan prove e bog
- Loading branch information
Showing
18 changed files
with
775 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,4 @@ jobs: | |
run: yarn install --frozen-lockfile | ||
|
||
- name: Run unit tests | ||
run: yarn test:unit | ||
run: yarn test:unit:once |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { HydrationBoundary, dehydrate } from "@tanstack/react-query" | ||
import React from "react" | ||
|
||
import WorkPageLayout from "@/components/pages/workPageLayout/WorkPageLayout" | ||
import getQueryClient from "@/lib/getQueryClient" | ||
import { useGetMaterialQuery } from "@/lib/graphql/generated/fbi/graphql" | ||
|
||
function Page({ params: { id } }: { params: { id: string } }) { | ||
const queryClient = getQueryClient() | ||
|
||
const decodedWid = decodeURIComponent(id) | ||
|
||
queryClient.prefetchQuery({ | ||
queryKey: useGetMaterialQuery.getKey({ wid: decodedWid }), | ||
queryFn: useGetMaterialQuery.fetcher({ wid: decodedWid }), | ||
}) | ||
|
||
return ( | ||
<HydrationBoundary state={dehydrate(queryClient)}> | ||
<div> | ||
<WorkPageLayout wid={decodedWid} /> | ||
<pre>{JSON.stringify(id, null, 2)}</pre> | ||
Page | ||
</div> | ||
</HydrationBoundary> | ||
) | ||
} | ||
|
||
export default Page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"use client" | ||
|
||
import { useQuery } from "@tanstack/react-query" | ||
import React from "react" | ||
|
||
import { useGetMaterialQuery } from "@/lib/graphql/generated/fbi/graphql" | ||
|
||
function WorkPageLayout({ wid }: { wid: string }) { | ||
const data = useQuery({ | ||
queryKey: useGetMaterialQuery.getKey({ wid }), | ||
queryFn: useGetMaterialQuery.fetcher({ wid }), | ||
}) | ||
|
||
return ( | ||
<div> | ||
<pre>{JSON.stringify({ data }, null, 2)}</pre> | ||
</div> | ||
) | ||
} | ||
|
||
export default WorkPageLayout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, { CSSProperties, useEffect } from "react" | ||
|
||
import { appendAsset, readerAssets } from "./helper" | ||
|
||
// type ReaderType = { identifier?: string; orderId?: string }; | ||
|
||
// Define mutually exclusive types for identifier and orderId | ||
type ReaderType = | ||
| { | ||
identifier: string | ||
orderId?: never | ||
} | ||
| { | ||
identifier?: never | ||
orderId: string | ||
} | ||
|
||
const Reader = ({ identifier, orderId }: ReaderType) => { | ||
useEffect(() => { | ||
readerAssets.forEach(appendAsset) | ||
}, [identifier, orderId]) | ||
|
||
const readerStyles: CSSProperties = { | ||
position: "absolute", | ||
top: "0", // Padding from the top | ||
left: "0", // Padding from the left | ||
right: "0", // Padding from the right | ||
bottom: "0", // Padding from the bottom | ||
padding: "20px", // Padding for the reader | ||
width: "100%", | ||
maxWidth: "unset", | ||
zIndex: 1000, | ||
// border: "1px dotted black", // Should be removed in production | ||
margin: "0", | ||
} | ||
|
||
const handleBack = () => { | ||
window.history.back() | ||
} | ||
|
||
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => { | ||
if (event.key === "Escape") { | ||
handleBack() | ||
} | ||
} | ||
|
||
if (orderId) { | ||
return ( | ||
<div> | ||
<p>orderId: {orderId}</p> | ||
<div | ||
style={readerStyles} | ||
id="pubhub-reader" | ||
// eslint-disable-next-line react/no-unknown-property | ||
order-id={orderId} | ||
role="button" | ||
tabIndex={0} | ||
onClick={handleBack} | ||
onKeyDown={handleKeyDown} | ||
aria-label="Go back" | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
if (identifier) { | ||
return ( | ||
<div | ||
style={readerStyles} | ||
id="pubhub-reader" | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
// eslint-disable-next-line react/no-unknown-property | ||
identifier={identifier} | ||
role="button" | ||
tabIndex={0} | ||
onClick={handleBack} | ||
onKeyDown={handleKeyDown} | ||
aria-label="Go back" | ||
/> | ||
) | ||
} | ||
|
||
return null | ||
} | ||
|
||
export default Reader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
type AssetType = { | ||
src: string | ||
type: "script" | "link" | ||
} | ||
|
||
export const readerAssets: AssetType[] = [ | ||
{ | ||
src: "https://reader.pubhub.dk/2.2.0/js/chunk-vendors.js", | ||
type: "script", | ||
}, | ||
{ | ||
src: "https://reader.pubhub.dk/2.2.0/js/app.js", | ||
type: "script", | ||
}, | ||
{ | ||
src: "https://reader.pubhub.dk/2.2.0/css/chunk-vendors.css", | ||
type: "link", | ||
}, | ||
{ | ||
src: "https://reader.pubhub.dk/2.2.0/css/app.css", | ||
type: "link", | ||
}, | ||
] | ||
|
||
export const appendAsset = ({ src, type }: AssetType) => { | ||
if (type === "script") { | ||
const scriptElement = document.createElement("script") | ||
scriptElement.src = src | ||
scriptElement.defer = true | ||
scriptElement.async = false | ||
scriptElement.type = "module" | ||
document.head.appendChild(scriptElement) | ||
} | ||
|
||
if (type === "link") { | ||
const linkElement = document.createElement("link") | ||
linkElement.href = src | ||
linkElement.rel = "stylesheet" | ||
document.head.appendChild(linkElement) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.