Skip to content

Commit a146aba

Browse files
authored
Merge branch 'master' into toc
2 parents ee32ee7 + c31a3a6 commit a146aba

File tree

7 files changed

+70
-17
lines changed

7 files changed

+70
-17
lines changed

app/components/Epub/index.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ class Epub extends Component {
4444
}
4545
});
4646

47-
this.book.ready.then(() => {
48-
if (this.props.onReady) this.props.onReady(this.book);
49-
});
50-
51-
this.book.loaded.metadata.then((nav) => {
52-
if (this.props.onMetadataReady) this.props.onMetadataReady(nav.toc);
53-
});
54-
5547
this.book.loaded.navigation.then((nav) => {
5648
if (this.props.onNavigationReady) this.props.onNavigationReady(nav.toc);
5749
});
@@ -68,8 +60,15 @@ class Epub extends Component {
6860
}
6961
};
7062

71-
this.rendition.on('keyup', this.keyListener);
72-
document.addEventListener('keyup', this.keyListener, false);
63+
this.book.ready.then(() => {
64+
if (this.props.onReady) this.props.onReady(this.book);
65+
this.rendition.on('keyup', this.keyListener);
66+
document.addEventListener('keyup', this.keyListener, false);
67+
});
68+
69+
this.book.loaded.navigation.then((nav) => {
70+
if (this.props.onNavigationReady) this.props.onNavigationReady(nav.toc);
71+
});
7372
}
7473

7574
componentWillUnmount() {

app/components/Loader/Loader.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.loader__container {
2+
position: absolute;
3+
top: 50%;
4+
left: 50%;
5+
right: 50%;
6+
bottom: 50%;
7+
display: flex;
8+
justify-content: center;
9+
align-items: center;
10+
font-size: 20px;
11+
text-align: center;
12+
flex-direction: column;
13+
14+
> div {
15+
padding: 20px 0;
16+
}
17+
}

app/components/Loader/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
import Spinner from 'react-spinkit';
3+
import './Loader.scss';
4+
5+
const Loader = () => (
6+
<div className="loader__container">
7+
Loading
8+
<Spinner
9+
spinnerName="chasing-dots"
10+
noFadeIn
11+
/>
12+
</div>
13+
);
14+
15+
export default Loader;

app/components/Reader/index.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
import React, { Component } from 'react';
22
import { Link } from 'react-router';
3+
import Loader from '../Loader';
34
import Epub from '../Epub';
45
import getStreamHost from '../../utils/get-stream-host';
56
import './Reader.scss';
67

78
class Reader extends Component {
89
constructor(props) {
910
super(props);
10-
this.state = {
11-
"nav": [],
12-
"location" : 0
13-
};
11+
this.handleReady = this.handleReady.bind(this);
1412
}
1513

1614
_navigationReady(nav) {
17-
this.setState({ nav });
15+
this.setState({ ...this.state, nav });
1816
}
1917

2018
_onNavClick(item) {
21-
this.setState({location : item.href })
19+
this.setState({ ...this.state, location: item.href });
2220
}
2321

2422
tocToggle() {
@@ -29,6 +27,17 @@ class Reader extends Component {
2927
} else {
3028
navMenu.classList.add('is-visible');
3129
}
30+
31+
}
32+
33+
state = {
34+
isLoading: true,
35+
nav: [],
36+
location : 0
37+
};
38+
39+
handleReady() {
40+
this.setState({ ...this.state, isLoading: false });
3241
}
3342

3443
render() {
@@ -76,6 +85,7 @@ class Reader extends Component {
7685
</a>
7786
</div>
7887
</nav>
88+
{this.state.isLoading && <Loader />}
7989
<Epub
8090
src={`${getStreamHost()}/${book.id}/${download}/`}
8191
onNavigationReady={ this._navigationReady.bind(this) }

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
"react": "^15.4.2",
148148
"react-dom": "^15.4.2",
149149
"react-router": "^3.0.2",
150+
"react-spinkit": "^2.0.0",
150151
"sass-loader": "^5.0.1",
151152
"source-map-support": "^0.4.10"
152153
},

webpack.config.base.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { dependencies as externals } from './app/package.json';
99
export default validate({
1010
module: {
1111
loaders: [{
12+
test: /\.css$/,
13+
loader: 'style!css'
14+
},
15+
{
1216
test: /\.jsx?$/,
1317
loaders: ['babel-loader'],
1418
exclude: /node_modules/

yarn.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ clap@^1.0.9:
16161616
dependencies:
16171617
chalk "^1.1.3"
16181618

1619-
classnames@^2.2.5:
1619+
classnames@^2.2.3, classnames@^2.2.5:
16201620
version "2.2.5"
16211621
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.5.tgz#fb3801d453467649ef3603c7d61a02bd129bde6d"
16221622

@@ -5250,6 +5250,13 @@ react-router@^3.0.2:
52505250
loose-envify "^1.2.0"
52515251
warning "^3.0.0"
52525252

5253+
react-spinkit@^2.0.0:
5254+
version "2.0.0"
5255+
resolved "https://registry.yarnpkg.com/react-spinkit/-/react-spinkit-2.0.0.tgz#1b010bc69f54bc2bdfa7587fcbab44c249bebdbe"
5256+
dependencies:
5257+
classnames "^2.2.3"
5258+
object-assign "^4.1.0"
5259+
52535260
react-transform-catch-errors@^1.0.2:
52545261
version "1.0.2"
52555262
resolved "https://registry.yarnpkg.com/react-transform-catch-errors/-/react-transform-catch-errors-1.0.2.tgz#1b4d4a76e97271896fc16fe3086c793ec88a9eeb"

0 commit comments

Comments
 (0)