Newer
Older
import { th, lighten } from '@pubsweet/ui-toolkit'
Center,
PreviewPage,
PreviewPanel,
EditPanel,
PanelHeader,
PanelContent,
import UploadFiles, { SubmissionTypes, ReviewTypes } from '../upload-files'
import ManuscriptPreview from '../ManuscriptPreview'
import PDFViewer from '../pdf-viewer'
import HTMLPreview from './HTMLPreview'
import ReviewForm from './ReviewForm'
import { CONVERT_XML, GET_REVIEWS } from './operations'
const PreviewPageDiv = styled(PreviewPage)`
& > div > div > div:last-child {
height: calc(100% - (${th('gridUnit')} * 19));
@media screen and (max-width: 870px) {
.show-mobile {
}
.hide-mobile {
display: none;
}
}
`
const PreviewPanelHeader = styled(PanelHeader)`
height: calc(${th('gridUnit')} * 10);
&.hide-mobile button {
margin-left: calc(${th('gridUnit')} * 3);
}
@media screen and (max-width: 870px) {
height: auto;
margin-bottom: calc(${th('gridUnit')} * 3);
}
const PreviewError = styled.div`
border: ${th('borderWidth')} ${th('borderStyle')} ${th('colorError')};
background-color: ${lighten('colorError', 40)};
padding: ${th('gridUnit')} calc(${th('gridUnit')} * 2);
margin: ${th('gridUnit')} 0;
const AnnotatePDF = Annotator(PDFViewer)
const AnnotateHTML = Annotator(HTMLPreview)
const allFileTypes = SubmissionTypes.concat(
ReviewTypes.reduce((all, t) => {
if (!SubmissionTypes.some(existing => existing.value === t.value)) {
all.push(t)
state = {
pane: this.props.currentUser.admin ? 'files' : 'web',
error: '',
showManuscript: false,
showAll: false,
const { manuscript, currentUser, reviews } = this.props
const [review] = reviews
const { files: allfiles, meta, status } = manuscript
const sourceFile = allfiles.find(f => f.type === 'manuscript')
f => !f.type || ReviewTypes.some(rev => rev.value === f.type),
const originalFiles = allfiles.filter(f =>
SubmissionTypes.some(sub => sub.value === f.type),
const html = files.find(file => file.type === 'tempHTML')
const pdf = files.find(f => f.type === 'pdf4load' || f.type === 'pdf4print')
const xml = files.find(f => f.type === 'PMC') || null
const xmlError = meta.notes
? meta.notes.find(n => n.notesType === 'xml error')
: ''
const { pane, error, showManuscript, showAll } = this.state
<PreviewPanel
style={{
flex: showManuscript && '1 1 750px',
width: showManuscript && '50%',
}}
>
<div style={{ maxWidth: showManuscript && '750px' }}>
<PreviewPanelHeader>
<H1>Review web versions of manuscript</H1>
</PreviewPanelHeader>
<Toggle>
onClick={() => this.setState({ pane: 'files' })}
>
onClick={() => {
this.setState({ pane: 'web' })
}}
>
</Action>
<Action
className={pane === 'pdf' ? 'current' : ''}
onClick={() => this.setState({ pane: 'pdf' })}
>
}
onClick={() => this.setState({ pane: 'original' })}
primary={pane !== 'original'}
>
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<Mutation mutation={CONVERT_XML}>
{(convertXML, { data }) => {
const generatePreviews = async () => {
await convertXML({
variables: { id: xml.id },
})
}
return (
<React.Fragment>
<Buttons left top>
<Button disabled={!xml} onClick={generatePreviews}>
Regenerate previews
</Button>
<Button
onClick={() => this.setState({ showAll: !showAll })}
>
{`${showAll ? 'Hide' : 'Show'} submission files`}
</Button>
</Buttons>
{xmlError && (
<PreviewError>
{ReactHtmlParser(xmlError.content)}
</PreviewError>
)}
{error && (
<Center>
<ErrorText>{error}</ErrorText>
</Center>
)}
<UploadFiles
checked
files={showAll ? allfiles : files}
manuscript={manuscript.id}
types={showAll ? allFileTypes : ReviewTypes}
/>
{error && (
<Center>
<ErrorText>{error}</ErrorText>
</Center>
)}
<Buttons left top>
<Button disabled={!xml} onClick={generatePreviews}>
Regenerate previews
</Button>
<Button
onClick={() => this.setState({ showAll: !showAll })}
>
{`${showAll ? 'Hide' : 'Show'} submission files`}
</Button>
</Buttons>
</React.Fragment>
)
}}
</Mutation>
<React.Fragment>
{status === 'tagging' ? (
<PDFViewer url={pdf.url} />
) : (
<AnnotatePDF
file={pdf}
revId={(review && review.id) || null}
userId={currentUser.id}
/>
)}
</React.Fragment>
<React.Fragment>
{status === 'tagging' ? (
<HTMLPreview url={html.url} />
) : (
<AnnotateHTML
file={html}
revId={(review && review.id) || null}
userId={currentUser.id}
/>
)}
</React.Fragment>
)}
{pane === 'original' && sourceFile && (
<ManuscriptPreview file={sourceFile} />
)}
</PanelContent>
</div>
</PreviewPanel>
<EditPanel
style={{
flex: showManuscript && '1 1 750px',
width: showManuscript && '50%',
}}
>
<div style={{ maxWidth: showManuscript && '750px' }}>
<PreviewPanelHeader>
<H2>Compare & approve</H2>
</PreviewPanelHeader>
<Toggle className="hide-mobile">
<Button
onClick={() =>
this.setState({ showManuscript: !showManuscript })
}
>
{showManuscript
: 'Compare with submitted file'}
</Button>
</Toggle>
<PanelContent className={showManuscript && 'pad'}>
{showManuscript && sourceFile ? (
<ManuscriptPreview file={sourceFile} />
) : (
<ReviewForm
annotations={(review && review.annotations) || []}
</div>
</EditPanel>
</PreviewPageDiv>
)
}
}
const ReviewWithHeader = SubmissionHeader(Review)
const ReviewPage = ({ match, ...props }) => (
<Query
fetchPolicy="cache-and-network"
query={GET_MANUSCRIPT}
variables={{ id: match.params.id }}
>
{({ data: { manuscript }, loading: loadingOne, refetch }) => (
<Query query={GET_REVIEWS} variables={{ manuscriptId: match.params.id }}>
{({ data, loading: loadingTwo }) => {
if (loadingOne || !manuscript) {
return (
<Loading>
<LoadingIcon />
</Loading>
)
}
return (
<ReviewWithHeader
manuscript={manuscript}
match={match}
reviews={(data && data.reviewsByMId) || []}
{...props}
/>
)
}}
</Query>
)}