2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-26 10:52:20 +02:00
|
|
|
import React from 'react';
|
2015-10-19 15:29:57 +02:00
|
|
|
import { History } from 'react-router';
|
2015-05-26 10:52:20 +02:00
|
|
|
|
2015-11-30 18:23:03 +01:00
|
|
|
import ReactError from '../../mixins/react_error';
|
|
|
|
import { ResourceNotFoundError } from '../../models/errors';
|
2015-05-26 10:52:20 +02:00
|
|
|
|
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-11-30 18:23:03 +01:00
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
2015-10-13 17:52:45 +02:00
|
|
|
import { setDocumentTitle } from '../../utils/dom_utils';
|
|
|
|
|
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-10-01 14:54:56 +02:00
|
|
|
propTypes: {
|
2015-10-28 11:26:54 +01:00
|
|
|
actionPanelButtonListType: React.PropTypes.func,
|
|
|
|
furtherDetailsType: React.PropTypes.func,
|
2016-01-11 12:54:15 +01:00
|
|
|
|
|
|
|
// Provided from AscribeApp
|
2016-02-05 11:53:33 +01:00
|
|
|
currentUser: React.PropTypes.object.isRequired,
|
|
|
|
whitelabel: React.PropTypes.object.isRequired,
|
2016-01-11 12:54:15 +01:00
|
|
|
|
2016-01-11 16:26:36 +01:00
|
|
|
// Provided from router
|
2016-01-11 12:54:15 +01:00
|
|
|
location: React.PropTypes.object,
|
2015-11-23 10:46:20 +01:00
|
|
|
params: React.PropTypes.object
|
2015-10-01 14:54:56 +02:00
|
|
|
},
|
|
|
|
|
2015-11-30 18:23:03 +01:00
|
|
|
mixins: [History, ReactError],
|
2015-10-19 15:29:57 +02:00
|
|
|
|
2015-05-26 10:52:20 +02:00
|
|
|
getInitialState() {
|
2016-02-05 10:38:59 +01:00
|
|
|
return EditionStore.getInitialState();
|
2015-05-26 10:52:20 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
2015-05-26 13:48:46 +02:00
|
|
|
EditionStore.listen(this.onChange);
|
2015-11-04 13:56:43 +01:00
|
|
|
|
2016-02-05 10:38:59 +01:00
|
|
|
this.loadEdition();
|
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) {
|
2016-01-11 12:54:15 +01:00
|
|
|
if (this.props.params.editionId !== nextProps.params.editionId) {
|
2016-02-05 10:38:59 +01:00
|
|
|
EditionActions.flushEdition();
|
|
|
|
this.loadEdition(nextProps.params.editionId);
|
2015-09-01 14:45:14 +02:00
|
|
|
}
|
|
|
|
},
|
2015-06-05 11:06:36 +02:00
|
|
|
|
2015-10-19 15:29:57 +02:00
|
|
|
componentDidUpdate() {
|
2016-02-05 10:38:59 +01:00
|
|
|
const { err: editionErr } = this.state.editionMeta;
|
|
|
|
|
|
|
|
if (editionErr && editionErr.json && editionErr.json.status === 404) {
|
2015-12-07 11:48:28 +01:00
|
|
|
this.throws(new ResourceNotFoundError(getLangText("Oops, the edition you're looking for doesn't exist.")));
|
2015-10-19 15:29:57 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-04 13:17:59 +02:00
|
|
|
componentWillUnmount() {
|
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-11-04 13:57:15 +01:00
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
2015-06-05 14:22:02 +02:00
|
|
|
},
|
|
|
|
|
2016-02-05 10:38:59 +01:00
|
|
|
loadEdition(editionId = this.props.params.editionId) {
|
|
|
|
EditionActions.fetchEdition(editionId);
|
|
|
|
},
|
|
|
|
|
2015-05-26 10:52:20 +02:00
|
|
|
render() {
|
2016-01-11 19:22:25 +01:00
|
|
|
const { actionPanelButtonListType, currentUser, furtherDetailsType, whitelabel } = this.props;
|
2016-01-11 12:54:15 +01:00
|
|
|
const { edition, coaMeta } = this.state;
|
2015-12-09 15:56:47 +01:00
|
|
|
|
2016-02-05 10:38:59 +01:00
|
|
|
if (edition.id) {
|
|
|
|
setDocumentTitle(`${edition.artist_name}, ${edition.title}`);
|
2015-12-09 15:56:47 +01:00
|
|
|
|
2015-05-26 10:52:20 +02:00
|
|
|
return (
|
2015-06-05 11:06:36 +02:00
|
|
|
<Edition
|
2015-12-09 15:56:47 +01:00
|
|
|
actionPanelButtonListType={actionPanelButtonListType}
|
2015-12-09 11:41:46 +01:00
|
|
|
coaError={coaMeta.err}
|
|
|
|
currentUser={currentUser}
|
2016-01-11 19:22:25 +01:00
|
|
|
edition={edition}
|
|
|
|
furtherDetailsType={furtherDetailsType}
|
2016-02-05 10:38:59 +01:00
|
|
|
loadEdition={this.loadEdition}
|
2016-01-11 19:22:25 +01:00
|
|
|
whitelabel={whitelabel} />
|
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;
|