2015-07-08 22:54:07 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import PieceActions from '../../actions/piece_actions';
|
|
|
|
import PieceStore from '../../stores/piece_store';
|
|
|
|
|
|
|
|
import Piece from './piece';
|
|
|
|
|
2015-07-13 15:21:09 +02:00
|
|
|
import AppConstants from '../../constants/application_constants';
|
|
|
|
|
2015-07-08 22:54:07 +02:00
|
|
|
/**
|
|
|
|
* This is the component that implements resource/data specific functionality
|
|
|
|
*/
|
|
|
|
let PieceContainer = React.createClass({
|
|
|
|
getInitialState() {
|
|
|
|
return PieceStore.getState();
|
|
|
|
},
|
|
|
|
|
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
PieceStore.listen(this.onChange);
|
|
|
|
PieceActions.fetchOne(this.props.params.pieceId);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
// Every time we're leaving the piece detail page,
|
|
|
|
// just reset the piece that is saved in the piece store
|
|
|
|
// as it will otherwise display wrong/old data once the user loads
|
|
|
|
// the piece detail a second time
|
|
|
|
PieceActions.updatePiece({});
|
|
|
|
|
|
|
|
PieceStore.unlisten(this.onChange);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
loadPiece() {
|
|
|
|
PieceActions.fetchOne(this.props.params.pieceId);
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if('title' in this.state.piece) {
|
|
|
|
return (
|
|
|
|
<Piece
|
|
|
|
piece={this.state.piece}
|
|
|
|
loadPiece={this.loadPiece}/>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
2015-07-13 15:00:12 +02:00
|
|
|
<div className="fullpage-spinner">
|
2015-07-13 15:21:09 +02:00
|
|
|
<img src={AppConstants.baseUrl + 'static/img/ascribe_animated_medium.gif'} />
|
2015-07-13 15:00:12 +02:00
|
|
|
</div>
|
2015-07-08 22:54:07 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default PieceContainer;
|