1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 09:50:31 +01:00
onion/js/components/edition_container.js

58 lines
1.4 KiB
JavaScript
Raw Normal View History

'use strict';
2015-05-26 10:52:20 +02:00
import React from 'react';
2015-05-26 13:48:46 +02:00
import EditionActions from '../actions/edition_actions';
import EditionStore from '../stores/edition_store';
2015-05-26 10:52:20 +02:00
2015-05-26 13:48:46 +02:00
import Edition from './edition';
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() {
return EditionStore.getState();
2015-05-26 10:52:20 +02:00
},
onChange(state) {
this.setState(state);
},
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
},
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-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-05-26 13:48:46 +02:00
if('title' in this.state.edition) {
2015-05-26 10:52:20 +02:00
return (
<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 (
<p>Loading</p>
);
}
}
});
2015-05-26 13:48:46 +02:00
export default EditionContainer;