-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourcePanel.tsx
More file actions
186 lines (176 loc) · 5.67 KB
/
SourcePanel.tsx
File metadata and controls
186 lines (176 loc) · 5.67 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import type { ReactElement } from 'react';
import Select from 'react-select';
import type { SingleValue } from 'react-select';
import { Info, X } from 'react-feather';
import manifests from '../../static/files/manifests';
import { ErrorBoundary } from '../ErrorBoundary/ErrorBoundary';
import { Mirador } from './Mirador';
import { PDFViewer } from './PDFViewer/PDFViewer';
import { Sources } from './sources.enum';
import styles from './SourcePanel.module.scss';
const sourceOptions: Option[] = [
{ label: 'CBL and UM images', value: Sources.Mirador },
{ label: 'Kenyon plates', value: Sources.KenyonPlates },
{ label: 'Peterson transcription', value: Sources.Peterson },
{ label: 'Kenyon transcription', value: Sources.KenyonText }
];
interface SourcePanelProps {
closeViewer: () => void;
manifestIndex: number;
onChange: (_newSelection: Sources) => void;
selectedSourcePanels: Array<Sources | null>;
source: Sources | null;
toggleGuideModal: () => void;
}
type Option = { label: string; value: string };
export const SourcePanel = ({
closeViewer,
manifestIndex,
onChange,
selectedSourcePanels,
source,
toggleGuideModal
}: SourcePanelProps): ReactElement => {
const handleSourceChange = (newSource: SingleValue<Option>): void => {
if (!newSource) {
return;
}
onChange(newSource.value as Sources);
};
const getContent = (): ReactElement | string => {
if (!source) {
return 'Select a source from the dropdown above';
}
return (
<ErrorBoundary>
{source === Sources.Mirador ? (
<Mirador
canvasIndex={manifests[manifestIndex].canvasIndex}
manifest={manifests[manifestIndex].url}
/>
) : (
<PDFViewer source={source} pageNumber={manifests[manifestIndex][`${source}Page`]} />
)}
</ErrorBoundary>
);
};
const getHelpText = (): ReactElement => {
if (source === Sources.Peterson) {
return (
<p className={styles.Item}>
Peterson, Jacob W. "GA 1739: A Monk, His Manuscript, and the Text of Paul's
Letters." PhD Thesis, University of Edinburgh, 2020. (
<a
href="http://dx.doi.org/10.7488/era/528"
target="_blank"
rel="noreferrer"
className={styles.Link}
>
doi.org/10.7488/era/528
</a>
)
</p>
);
} else if (source === Sources.KenyonText) {
return (
<p className={styles.Item}>
Kenyon, Frederic G., ed.{' '}
<i>
The Chester Beatty Biblical Papyri, Fasciculus III, Supplement: Pauline Epistles, Text.
</i>{' '}
London: Emery Walker, 1936.
</p>
);
} else if (source === Sources.KenyonPlates) {
return (
<p className={styles.Item}>
Kenyon, Frederic G., ed.{' '}
<i>
The Chester Beatty Biblical Papyri, Fasciculus III, Supplement: Pauline Epistles,
Plates.
</i>{' '}
London: Emery Walker, 1937.
</p>
);
} else {
return (
<p className={styles.Item}>
Images from both the Chester Beatty Library and University of Michigan Library are
provided under a Creative Commons license. For more information, see{' '}
<a
href="https://chesterbeatty.ie/about/copyright-2/"
target="_blank"
rel="noreferrer"
className={styles.Link}
>
Chester Beatty Library
</a>{' '}
and{' '}
<a
href="https://quod.lib.umich.edu/a/apis/x-3553/6238_30.TIF?lasttype=boolean;lastview=reslist;resnum=1;size=50;sort=apis_inv;start=1;subview=detail;view=entry;rgn1=apis_inv;select1=phrase;q1=P.Mich.inv.+6238#rights-permissions"
target="_blank"
rel="noreferrer"
className={styles.Link}
>
University of Michigan Library
</a>
</p>
);
}
};
return (
<div className={styles.Container}>
<div className={styles.Header}>
<Select
aria-label="Choose viewer source"
classNames={{
control: () => styles.Control,
menu: () => styles.Menu,
option: () => styles.Option
}}
theme={theme => ({
...theme,
colors: {
...theme.colors,
primary: '#00333d',
primary25: '#dbf5fb',
primary50: '#00667a'
}
})}
value={sourceOptions.find(({ value }) => value === source) || null}
onChange={handleSourceChange}
captureMenuScroll
menuShouldBlockScroll
options={sourceOptions.filter(
option => !selectedSourcePanels.includes(option.value as Sources)
)}
isSearchable
/>
<div className={styles.EndButtons}>
{source === Sources.Peterson && (
<button
aria-label="Help"
onClick={toggleGuideModal}
className={styles.TranscriptionGuideButton}
>
Help
</button>
)}
<div aria-label="info tooltip" className={styles.Tooltip} tabIndex={0} role="button">
<Info size={18} />
<span className={styles.TooltipText}>{getHelpText()}</span>
</div>
<button
aria-label="Close viewer"
onClick={closeViewer}
className={styles.IconButton}
disabled={selectedSourcePanels.length < 2}
>
<X />
</button>
</div>
</div>
<div className={styles.Content}>{getContent()}</div>
</div>
);
};