1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00
onion/js/components/ascribe_detail/edition_container.js

85 lines
2.6 KiB
JavaScript
Raw Normal View History

'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
import AppConstants from '../../constants/application_constants';
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({
propTypes: {
location: React.PropTypes.object
},
2015-05-26 10:52:20 +02:00
getInitialState() {
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-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);
}
},
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() {
if(this.state.edition && this.state.edition.title) {
2015-05-26 10:52:20 +02:00
return (
<Edition
edition={this.state.edition}
loadEdition={this.loadEdition}
location={this.props.location}/>
2015-05-26 10:52:20 +02:00
);
} else {
return (
<div className="fullpage-spinner">
<img src={AppConstants.baseUrl + 'static/img/ascribe_animated_medium.gif'} />
</div>
2015-05-26 10:52:20 +02:00
);
}
}
});
2015-05-26 13:48:46 +02:00
export default EditionContainer;