-
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 #55 from danskernesdigitalebibliotek/DDFBRA-200-an…
…onym-og-indlogget-bruger-kan-prove-e-bog feat: add reader page to show publizon reader and enhance work page layout with smartLink
- Loading branch information
Showing
13 changed files
with
157 additions
and
78 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 |
---|---|---|
@@ -1,22 +1,26 @@ | ||
import { expect, test } from "vitest" | ||
|
||
import goConfig from "@/lib/config/config" | ||
|
||
import { resolveUrl } from "../lib/helpers/helper.routes" | ||
|
||
test("That resolveUrl can return a work url", async () => { | ||
const workUrl = resolveUrl({ type: "work", routeParams: { wid: 123 } }) | ||
expect(workUrl).toBe("/work/123") | ||
const workUrl = resolveUrl({ routeParams: { work: "work", wid: 123 } }) | ||
const appUrl = goConfig("app.url") | ||
expect(workUrl).toBe(`${appUrl}/work/123`) | ||
}) | ||
|
||
test("That resolveUrl can return a work url with a manifestation type", async () => { | ||
const workUrl = resolveUrl({ | ||
type: "work", | ||
routeParams: { wid: 123 }, | ||
routeParams: { work: "work", wid: 123 }, | ||
queryParams: { audio: "true" }, | ||
}) | ||
expect(workUrl).toBe("/work/123?audio=true") | ||
const appUrl = goConfig("app.url") | ||
expect(workUrl).toBe(`${appUrl}/work/123?audio=true`) | ||
}) | ||
|
||
test("That resolveUrl can return a search url", async () => { | ||
const workUrl = resolveUrl({ type: "search", queryParams: { q: "test" } }) | ||
expect(workUrl).toBe("/search?q=test") | ||
const workUrl = resolveUrl({ routeParams: { search: "search" }, queryParams: { q: "test" } }) | ||
const appUrl = goConfig("app.url") | ||
expect(workUrl).toBe(`${appUrl}/search?q=test`) | ||
}) |
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,20 @@ | ||
"use client" | ||
|
||
import React from "react" | ||
|
||
import Reader from "@/components/shared/publizonReader/PublizonReader" | ||
|
||
function Page({ searchParams: { id } }: { searchParams: { id: string } }) { | ||
const handleBack = () => { | ||
window.history.back() | ||
} | ||
|
||
return ( | ||
<div className="absolute inset-0 h-screen w-screen"> | ||
<div className="absolute h-full w-full bg-reader-grey"></div> | ||
<Reader onBackCallback={() => handleBack()} type="demo" identifier={id} /> | ||
</div> | ||
) | ||
} | ||
|
||
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
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,36 @@ | ||
import Link from "next/link" | ||
import React from "react" | ||
|
||
function SmartLink({ | ||
href, | ||
target = "_self", | ||
linkType = "internal", | ||
children, | ||
className, | ||
}: { | ||
href: string | ||
target?: string | ||
linkType?: "internal" | "external" | ||
children: React.ReactNode | ||
className?: string | ||
}) { | ||
// Internal link | ||
if (linkType === "internal") { | ||
return ( | ||
<Link className={className} href={href} target={target}> | ||
{children} | ||
</Link> | ||
) | ||
} | ||
|
||
// External link | ||
if (linkType === "external") { | ||
return ( | ||
<a className={className} href={href} target={target}> | ||
{children} | ||
</a> | ||
) | ||
} | ||
} | ||
|
||
export default SmartLink |
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 |
---|---|---|
@@ -1,60 +1,54 @@ | ||
import goConfig from "../config/config" | ||
|
||
type RouteParams = { [key: string]: string | number } | ||
type QueryParams = { [key: string]: string | number } | ||
|
||
export function buildRoute({ | ||
route, | ||
params, | ||
query, | ||
}: { | ||
route: string | ||
params?: RouteParams | ||
query?: QueryParams | ||
}): string { | ||
let routeParams = "" | ||
if (params) { | ||
route = Object.keys(params).reduce((acc, key) => { | ||
routeParams = Object.keys(params).reduce((acc, key) => { | ||
const value = encodeURIComponent(params[key]) | ||
return acc.replace(`:${key}`, value) | ||
}, route) | ||
return `${acc}/${value}` | ||
}, routeParams) | ||
} | ||
|
||
const queryParams = new URLSearchParams() | ||
const url = new URL(routeParams, goConfig("app.url")) | ||
if (query) { | ||
Object.keys(query).forEach(key => { | ||
queryParams.append(key, query[key].toString()) | ||
url.searchParams.append(key, query[key].toString()) | ||
}) | ||
} | ||
|
||
if (queryParams.toString()) { | ||
return `${route}?${queryParams}` | ||
} | ||
|
||
return route | ||
return url.toString() | ||
} | ||
|
||
type ResolveUrlOptions = | ||
| { | ||
type: "work" | ||
routeParams?: { wid: number | string } | ||
routeParams?: { work: "work"; wid: number | string } | ||
queryParams?: QueryParams | ||
} | ||
| { | ||
type: "search" | ||
routeParams?: undefined | ||
routeParams?: { work: "work"; ":wid": number | string; read: "read" } | ||
queryParams?: QueryParams | ||
} | ||
| { | ||
routeParams?: { search: "search" } | ||
queryParams?: QueryParams | ||
} | ||
|
||
export const resolveUrl = ({ type, routeParams, queryParams }: ResolveUrlOptions) => { | ||
switch (type as ResolveUrlOptions["type"]) { | ||
case "work": | ||
if (!routeParams?.wid) return "" | ||
return buildRoute({ | ||
route: "/work/:wid", | ||
params: { wid: routeParams.wid }, | ||
query: queryParams, | ||
}) | ||
case "search": | ||
return buildRoute({ route: "/search", query: queryParams }) | ||
default: | ||
return "" | ||
export const resolveUrl = ({ routeParams, queryParams }: ResolveUrlOptions) => { | ||
if (!routeParams) { | ||
throw new Error("routeParams is required") | ||
} | ||
|
||
return buildRoute({ | ||
params: routeParams, | ||
query: queryParams, | ||
}) | ||
} |
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,3 @@ | ||
import { cn as classNames } from "../helpers/helper.cn" | ||
|
||
export const cn = classNames |
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
Oops, something went wrong.