Skip to content

Commit a81ba36

Browse files
authored
SCHOL-305: Implement new web reader designs (#190)
* initial design changes * update html settings * implement reset settings and current page for PDFs * add fit to height and width functionality for pdf * implement fit to height/width for HTMLReader * fix flickering on pdf reader * add tooltips * fix scrolling fit to height zoom issue * add rotate left functionality * address comment, update epub settings menu and icon sizes * fix chapter nav * implement full screen * update and remove tests * update unit tests * fix scaling issue * update playwright test to run against localhost * remove console log and fix flickering issue * SCHOL-314: Re-enable and update pdf tests (#191) * re-enable pdf tests and add test for page input * fix flaky locator * address comments
1 parent a7206fc commit a81ba36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1781
-1462
lines changed

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ Basic usage within a React app, using the default UI:
4141
import WebReader from '@nypl/web-reader';
4242

4343
const ReaderPage = ({ manifestUrl }) => {
44-
return (
45-
<WebReader
46-
webpubManifest={manifestUrl}
47-
headerLeft={<button>Back to app</button>}
48-
/>
49-
);
44+
return <WebReader webpubManifest={manifestUrl} />;
5045
};
5146
```
5247

example/index.tsx

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
import 'react-app-polyfill/ie11';
1+
import {
2+
Box,
3+
Button,
4+
ChakraProvider,
5+
Heading,
6+
Input,
7+
ListItem,
8+
Stack,
9+
Text,
10+
UnorderedList,
11+
} from '@chakra-ui/react';
212
import * as React from 'react';
13+
import 'react-app-polyfill/ie11';
314
import { createRoot } from 'react-dom/client';
415
import {
516
BrowserRouter,
6-
Switch,
7-
Route,
817
Link,
18+
Route,
19+
Switch,
920
useParams,
1021
} from 'react-router-dom';
11-
import WebReader, { addTocToManifest } from '../src';
12-
import {
13-
ChakraProvider,
14-
Heading,
15-
UnorderedList,
16-
ListItem,
17-
Box,
18-
Text,
19-
Input,
20-
Button,
21-
Stack,
22-
} from '@chakra-ui/react';
23-
import { getTheme } from '../src/ui/theme';
22+
import useSWR, { Fetcher } from 'swr';
23+
import readiumAfter from 'url:../src/HtmlReader/ReadiumCss/ReadiumCSS-after.css';
2424
import readiumBefore from 'url:../src/HtmlReader/ReadiumCss/ReadiumCSS-before.css';
2525
import readiumDefault from 'url:../src/HtmlReader/ReadiumCss/ReadiumCSS-default.css';
26-
import readiumAfter from 'url:../src/HtmlReader/ReadiumCss/ReadiumCSS-after.css';
27-
import Tests from './Tests';
26+
import WebReader, { addTocToManifest } from '../src';
2827
import { Injectable } from '../src/Readium/Injectable';
29-
import useSWR, { Fetcher } from 'swr';
30-
import UseHtmlReader from './use-html-reader';
28+
import { WebpubManifest } from '../src/types';
29+
import { getTheme } from '../src/ui/theme';
3130
import mobyEpub2Manifest from './static/samples/moby-epub2-exploded/manifest.json';
3231
import pdfSingleResourceManifest from './static/samples/pdf/single-resource-short.json';
33-
import { WebpubManifest } from '../src/types';
32+
import Tests from './Tests';
33+
import UseHtmlReader from './use-html-reader';
3434
import UsePdfReader from './use-pdf-reader';
3535

3636
const origin = window.location.origin;
@@ -101,6 +101,10 @@ const App = () => {
101101
};
102102

103103
const PdfReaders = () => {
104+
const [isFullViewport, setIsFullViewport] = React.useState(false);
105+
106+
const toggleFullScreen = () => setIsFullViewport((v) => !v);
107+
104108
return (
105109
<>
106110
<Route path={`/pdf/single-resource-short`}>
@@ -136,12 +140,23 @@ const PdfReaders = () => {
136140
instead of taking over the full page. It is fixed height, which
137141
means it will not grow to fit content in scrolling mode.
138142
</Text>
139-
<WebReader
140-
webpubManifestUrl={`${origin}/samples/pdf/multi-resource.json`}
141-
proxyUrl={pdfProxyUrl}
142-
pdfWorkerSrc={`${origin}/pdf-worker/pdf.worker.min.mjs`}
143-
growWhenScrolling={false}
144-
/>
143+
<Box
144+
margin="0 auto"
145+
width={isFullViewport ? '100vw' : '50%'}
146+
height={isFullViewport ? '100vh' : 'auto'}
147+
position={isFullViewport ? 'fixed' : 'relative'}
148+
top={isFullViewport ? 0 : undefined}
149+
left={isFullViewport ? 0 : undefined}
150+
zIndex={isFullViewport ? 9999 : undefined}
151+
>
152+
<WebReader
153+
webpubManifestUrl={`${origin}/samples/pdf/single-resource-short.json`}
154+
proxyUrl={pdfProxyUrl}
155+
pdfWorkerSrc={`${origin}/pdf-worker/pdf.worker.min.mjs`}
156+
growWhenScrolling={false}
157+
toggleFullScreen={toggleFullScreen}
158+
/>
159+
</Box>
145160
<Heading>The page continues...</Heading>
146161
<Text as="p">Here is some more content below the reader</Text>
147162
</Box>

example/static/samples/pdf/single-resource-short.json

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,34 @@
22
"context": "https://drb-files-qa-s3.amazonaws.com/manifests/context.jsonld",
33
"metadata": {
44
"@type": "https://schema.org/Book",
5-
"title": "EIB Working Paper 2021/03 - Assessing climate change risks at the country level",
5+
"title": "Annual exhibition",
66
"author": "Ferrazzi, Matteo",
77
"conformsTo": "http://librarysimplified.org/terms/profiles/pdf"
88
},
99
"links": [
1010
{
11-
"href": "https://library.oapen.org/bitstream/20.500.12657/50076/1/9789286150340.pdf",
11+
"href": "https://drb-files-qa.s3.us-east-1.amazonaws.com/tagged_pdfs/33433131779294.pdf",
1212
"type": "application/pdf",
1313
"rel": "alternate"
14-
},
15-
{
16-
"rel": "self",
17-
"href": "https://drb-files-qa.s3.amazonaws.com/manifests/doab/20.500.12854/71362.json",
18-
"type": "application/webpub+json"
1914
}
2015
],
2116
"readingOrder": [
2217
{
23-
"href": "https://library.oapen.org/bitstream/20.500.12657/50076/1/9789286150340.pdf",
24-
"title": "EIB Working Paper 2021/03 - Assessing climate change risks at the country level",
18+
"href": "https://drb-files-qa.s3.us-east-1.amazonaws.com/tagged_pdfs/33433131779294.pdf",
19+
"title": "Annual exhibition",
2520
"type": "application/pdf"
2621
}
2722
],
2823
"resources": [
2924
{
30-
"href": "https://library.oapen.org/bitstream/20.500.12657/50076/1/9789286150340.pdf",
25+
"href": "https://drb-files-qa.s3.us-east-1.amazonaws.com/tagged_pdfs/33433131779294.pdf",
3126
"type": "application/pdf"
3227
}
3328
],
3429
"toc": [
3530
{
36-
"href": "https://library.oapen.org/bitstream/20.500.12657/50076/1/9789286150340.pdf",
37-
"title": "EIB Working Paper 2021/03 - Assessing climate change risks at the country level"
31+
"href": "https://drb-files-qa.s3.us-east-1.amazonaws.com/tagged_pdfs/33433131779294.pdf",
32+
"title": "Annual exhibition"
3833
}
3934
]
40-
}
35+
}

example/use-html-reader.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import { useHtmlReader } from '../src';
33
import { Injectable } from '../src/Readium/Injectable';
44
import { WebpubManifest } from '../src/types';
5-
import Footer from '../src/ui/Footer';
65
import Header from '../src/ui/Header';
76

87
type HTMLReaderProps = {
@@ -34,13 +33,8 @@ const UseHtmlReader: React.FC<HTMLReaderProps> = ({
3433

3534
return (
3635
<div>
37-
<Header
38-
{...reader}
39-
headerLeft={<a href="/">Back</a>}
40-
containerRef={containerRef}
41-
/>
36+
<Header {...reader} containerRef={containerRef} />
4237
{reader.content}
43-
<Footer {...reader} />
4438
</div>
4539
);
4640
};

example/use-pdf-reader.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import { usePdfReader } from '../src';
33
import { WebpubManifest } from '../src/types';
4-
import Footer from '../src/ui/Footer';
54
import Header from '../src/ui/Header';
65

76
type PDFReaderProps = {
@@ -34,16 +33,11 @@ const UsePdfReader: React.FC<PDFReaderProps> = ({
3433
return null;
3534
}
3635

37-
const { content, ...readerProps } = reader;
36+
const { content } = reader;
3837
return (
3938
<div>
40-
<Header
41-
{...reader}
42-
headerLeft={<a href="/">Back</a>}
43-
containerRef={containerRef}
44-
/>
39+
<Header {...reader} containerRef={containerRef} />
4540
{content}
46-
<Footer {...readerProps} />
4741
</div>
4842
);
4943
};

playwright.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { defineConfig, devices } from '@playwright/test';
1111
/**
1212
* See https://playwright.dev/docs/test-configuration.
1313
*/
14+
1415
export default defineConfig({
1516
testDir: './playwright',
1617
/* Run tests in files in parallel */
@@ -26,7 +27,7 @@ export default defineConfig({
2627
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2728
use: {
2829
/* Base URL to use in actions like `await page.goto('/')`. */
29-
baseURL: 'https://nypl-web-reader.vercel.app/',
30+
baseURL: 'http://localhost:1234/',
3031

3132
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3233
trace: 'on-first-retry',

0 commit comments

Comments
 (0)