2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-26 10:52:20 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
2015-07-08 22:54:07 +02:00
|
|
|
import EditionActions from '../../actions/edition_actions';
|
|
|
|
import EditionStore from '../../stores/edition_store';
|
2015-05-26 10:52:20 +02:00
|
|
|
|
2015-07-08 22:54:07 +02:00
|
|
|
import Edition from './edition';
|
2015-05-26 10:52:20 +02:00
|
|
|
|
2015-10-12 15:25:21 +02:00
|
|
|
import AscribeSpinner from '../ascribe_spinner';
|
2015-09-02 14:02:23 +02:00
|
|
|
|
|
|
|
|
2015-05-26 10:52:20 +02:00
|
|
|
/**
|
|
|
|
* This is the component that implements resource/data specific functionality
|
|
|
|
*/
|
2015-05-26 13:48:46 +02:00
|
|
|
let EditionContainer = React.createClass({
|
2015-05-26 10:52:20 +02:00
|
|
|
getInitialState() {
|
2015-06-11 15:03:55 +02:00
|
|
|
return EditionStore.getState();
|
2015-05-26 10:52:20 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
2015-07-15 18:00:43 +02:00
|
|
|
if (!state.edition.digital_work) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let isEncoding = state.edition.digital_work.isEncoding;
|
|
|
|
if (state.edition.digital_work.mime === 'video' && typeof isEncoding === 'number' && isEncoding !== 100 && !this.state.timerId) {
|
2015-07-03 15:05:14 +02:00
|
|
|
let timerId = window.setInterval(() => EditionActions.fetchOne(this.props.params.editionId), 10000);
|
2015-07-08 13:05:15 +02:00
|
|
|
this.setState({timerId: timerId});
|
2015-07-03 15:05:14 +02:00
|
|
|
}
|
2015-05-26 10:52:20 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
2015-05-26 13:48:46 +02:00
|
|
|
EditionStore.listen(this.onChange);
|
2015-06-04 13:16:19 +02:00
|
|
|
EditionActions.fetchOne(this.props.params.editionId);
|
2015-05-26 10:52:20 +02:00
|
|
|
},
|
2015-06-05 11:06:36 +02:00
|
|
|
|
2015-09-01 14:45:14 +02:00
|
|
|
// This is done to update the container when the user clicks on the prev or next
|
|
|
|
// button to update the URL parameter (and therefore to switch pieces)
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if(this.props.params.editionId !== nextProps.params.editionId) {
|
|
|
|
EditionActions.updateEdition({});
|
|
|
|
EditionActions.fetchOne(nextProps.params.editionId);
|
|
|
|
}
|
|
|
|
},
|
2015-06-05 11:06:36 +02:00
|
|
|
|
2015-06-04 13:17:59 +02:00
|
|
|
componentWillUnmount() {
|
2015-07-01 15:23:50 +02:00
|
|
|
// Every time we're leaving the edition detail page,
|
|
|
|
// just reset the edition that is saved in the edition store
|
|
|
|
// as it will otherwise display wrong/old data once the user loads
|
|
|
|
// the edition detail a second time
|
|
|
|
EditionActions.updateEdition({});
|
2015-07-03 15:05:14 +02:00
|
|
|
window.clearInterval(this.state.timerId);
|
2015-05-26 13:48:46 +02:00
|
|
|
EditionStore.unlisten(this.onChange);
|
2015-05-26 10:52:20 +02:00
|
|
|
},
|
|
|
|
|
2015-06-05 14:22:02 +02:00
|
|
|
|
2015-06-09 13:29:22 +02:00
|
|
|
loadEdition() {
|
|
|
|
EditionActions.fetchOne(this.props.params.editionId);
|
2015-06-05 14:22:02 +02:00
|
|
|
},
|
|
|
|
|
2015-05-26 10:52:20 +02:00
|
|
|
render() {
|
2015-09-10 14:00:59 +02:00
|
|
|
if(this.state.edition && this.state.edition.title) {
|
2015-05-26 10:52:20 +02:00
|
|
|
return (
|
2015-06-05 11:06:36 +02:00
|
|
|
<Edition
|
|
|
|
edition={this.state.edition}
|
2015-06-09 13:29:22 +02:00
|
|
|
loadEdition={this.loadEdition}/>
|
2015-05-26 10:52:20 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
2015-07-13 15:21:09 +02:00
|
|
|
<div className="fullpage-spinner">
|
2015-10-12 15:25:21 +02:00
|
|
|
<AscribeSpinner color='dark-blue' size='lg'/>
|
2015-07-13 15:21:09 +02:00
|
|
|
</div>
|
2015-05-26 10:52:20 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-26 13:48:46 +02:00
|
|
|
export default EditionContainer;
|