-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathEndlessViewer.jsx
More file actions
95 lines (81 loc) · 2.62 KB
/
Copy pathEndlessViewer.jsx
File metadata and controls
95 lines (81 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import React, { useState } from 'react';
import { CgDebug, CgArrowsExpandDownRight } from 'react-icons/cg';
import { RiImageEditFill } from 'react-icons/ri';
import { BiSave } from "react-icons/bi";
import AnnotatablePage from './AnnotatablePage';
import { saveAs } from 'file-saver';
const Range = maxValue =>
Array.from(Array(maxValue).keys());
const EndlessViewer = props => {
const [ debug, setDebug ] = useState(false);
const [ annotationMode, setAnnotationMode ] = useState('ANNOTATION');
const onToggleRelationsMode = () => {
if (annotationMode === 'RELATIONS')
setAnnotationMode('ANNOTATION');
else
setAnnotationMode('RELATIONS');
}
const onToggleImageMode = () => {
if (annotationMode === 'IMAGE')
setAnnotationMode('ANNOTATION');
else
setAnnotationMode('IMAGE');
}
const saveAnnotationsToJson = () => {
const fileData = JSON.stringify(props.store.getAnnotations());
const blob = new Blob([fileData], { type: "application/json" });
saveAs(blob, props.url + '-annotations.json');
}
return (
<div>
<header>
<button onClick={() => setDebug(!debug)}>
<span className="inner">
<CgDebug />
</span>
</button>
<button
className={annotationMode === 'RELATIONS' ? 'active' : null}
onClick={onToggleRelationsMode}>
<span className="inner">
<CgArrowsExpandDownRight />
</span>
</button>
<button
className={annotationMode === 'IMAGE' ? 'active' : null}
onClick={onToggleImageMode}>
<span className="inner">
<RiImageEditFill />
</span>
</button>
<button
onClick={saveAnnotationsToJson}>
<span className="inner">
<BiSave />
</span>
</button>
</header>
<main>
<div className="pdf-viewer-container">
{Range(props.pdf.numPages).map(idx =>
<AnnotatablePage
key={idx}
url={props.url}
pdf={props.pdf}
page={idx + 1}
config={props.config}
debug={debug}
store={props.store}
connections={props.connections}
annotationMode={annotationMode}
onCreateAnnotation={props.onCreateAnnotation}
onUpdateAnnotation={props.onUpdateAnnotation}
onDeleteAnnotation={props.onDeleteAnnotation}
onCancelSelected={props.onCancelSelected} />
)}
</div>
</main>
</div>
)
}
export default EndlessViewer;