Skip to content

Commit c3aa4ed

Browse files
committed
update main view {pdf + form}
1 parent 0f74ddf commit c3aa4ed

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

src/App.js

+53-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import * as React from 'react';
2+
import { useState } from 'react'
23
import { Viewer, Worker, Popover, Position, Tooltip} from '@react-pdf-viewer/core';
34
import { defaultLayoutPlugin } from '@react-pdf-viewer/default-layout';
45
import { searchPlugin } from '@react-pdf-viewer/search';
6+
import SelectionHandler from './SelectionHandler';
7+
import PhraseForm from './PhraseForm'
58

69
// Import styles
710
import '@react-pdf-viewer/search/lib/styles/index.css';
@@ -10,6 +13,19 @@ import '@react-pdf-viewer/core/lib/styles/index.css';
1013
import '@react-pdf-viewer/default-layout/lib/styles/index.css';
1114

1215
const App = () => {
16+
const [phrase, setPhrase] = useState('')
17+
const [context, setContext] = useState('')
18+
19+
const onSelectionChange = (selection) => {
20+
setContext(selection.anchorNode.data)
21+
setPhrase(selection.toString())
22+
console.log(selection);
23+
}
24+
25+
const onSavePhrase = (phrase, context, meaning) => {
26+
console.log("here: " + phrase);
27+
setData([...data, phrase])
28+
}
1329

1430
const renderHighlights = React.useCallback(
1531
(renderProps) => {
@@ -70,7 +86,7 @@ const App = () => {
7086

7187

7288

73-
const data = ['Liberation', 'National Security', 'throughout', 'Cybersecurity was by then already a hot topic', 'conference', 'This project', 'should', 'States', 'Group', 'Opening', 'pdf', 'example', 'File', 'includes', 'content', 'could', 'new work', 'Parameters', 'agreement']
89+
const [data, setData] = useState(['Liberation', 'National Security', 'throughout', 'Cybersecurity was by then already a hot topic', 'conference', 'This project', 'should', 'States', 'Group', 'Opening', 'pdf', 'example', 'File', 'includes', 'content', 'could', 'new work', 'Parameters', 'agreement'])
7490
const searchPluginInstance = searchPlugin({
7591
keyword: [
7692
...data.map(text => new RegExp(text))
@@ -84,22 +100,46 @@ const App = () => {
84100

85101
const defaultLayoutPluginInstance = defaultLayoutPlugin();
86102

103+
104+
const styles = {
105+
splitScreen: {
106+
display: 'flex',
107+
flexDirection: 'row',
108+
},
109+
topPane: {
110+
width: '60%',
111+
},
112+
bottomPane: {
113+
width: '40%',
114+
},
115+
}
116+
117+
87118
return (
88119
<Worker workerUrl="https://unpkg.com/[email protected]/build/pdf.worker.js">
89-
<div
90-
style={{
91-
height: '750px',
92-
width: '900px',
93-
marginLeft: 'auto',
94-
marginRight: 'auto',
95-
}}
96-
>
97-
<Viewer
98-
fileUrl={`${process.env.PUBLIC_URL}/pdf-open-parameters.pdf`}
99-
plugins={[defaultLayoutPluginInstance, searchPluginInstance]}
100-
/>
120+
<div style={styles.splitScreen}>
121+
<div style={styles.topPane}>
122+
<div
123+
style={{
124+
height: '100vh',
125+
// width: '900px',
126+
marginLeft: 'auto',
127+
marginRight: 'auto',
128+
}}
129+
>
130+
<Viewer
131+
fileUrl={`${process.env.PUBLIC_URL}/pdf-open-parameters.pdf`}
132+
plugins={[defaultLayoutPluginInstance, searchPluginInstance]}
133+
/>
134+
<SelectionHandler phrase={phrase} onSelectionChange={onSelectionChange}/>
135+
</div>
136+
</div>
137+
<div style={styles.bottomPane}>
138+
<PhraseForm phrase={phrase} context={context} onSavePhrase={onSavePhrase}/>
139+
</div>
101140
</div>
102141
</Worker>
142+
103143
);
104144
};
105145

src/app.css

Whitespace-only changes.

0 commit comments

Comments
 (0)