forked from rage/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (49 loc) · 1.41 KB
/
Copy pathindex.js
File metadata and controls
56 lines (49 loc) · 1.41 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
import React, { Fragment, lazy, Suspense } from "react"
import { Paper } from "@material-ui/core"
import styled from "styled-components"
import withSimpleErrorBoundary from "../../util/withSimpleErrorBoundary"
import Loading from "../../components/Loading"
const PdfSlideshow = lazy(() => import("./PdfSlideshowLoader"))
const HiddenLinkWrapper = styled.div`
display: none;
`
const StyledPaper = styled(Paper)`
@media only screen and (max-width: 800px) {
overflow-y: scroll;
}
`
class PdfSlideshowWrapper extends React.Component {
state = {
render: false,
path: undefined,
}
constructor(props) {
super(props)
this.linkContainer = React.createRef()
}
componentDidMount() {
const links = this.linkContainer.current
const path = links.querySelector("a").href
this.setState({ render: true, path })
}
render() {
if (!this.state.render) {
return (
<Fragment>
<Loading loading={true} heightHint="540px" />
<HiddenLinkWrapper ref={this.linkContainer}>
{this.props.children}
</HiddenLinkWrapper>
</Fragment>
)
}
return (
<Suspense fallback={<div style={{ height: "540px" }}>Loading...</div>}>
<StyledPaper>
<PdfSlideshow slideWidth={800} pdfLocation={this.state.path} />
</StyledPaper>
</Suspense>
)
}
}
export default withSimpleErrorBoundary(PdfSlideshowWrapper)