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-12-08 13:28:47 +01:00
|
|
|
import UserActions from '../../actions/user_actions';
|
|
|
|
import UserStore from '../../stores/user_store';
|
|
|
|
|
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-12-08 13:28:47 +01:00
|
|
|
import { mergeOptions } from '../../utils/general_utils';
|
2015-10-13 17:52:45 +02:00
|
|
|
|
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,
|
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() {
|
2015-12-08 13:28:47 +01:00
|
|
|
return mergeOptions(
|
2016-01-13 17:24:32 +01:00
|
|
|
EditionStore.getInitialState(),
|
2015-12-08 13:28:47 +01:00
|
|
|
UserStore.getState()
|
|
|
|
);
|
2015-05-26 10:52:20 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
2015-05-26 13:48:46 +02:00
|
|
|
EditionStore.listen(this.onChange);
|
2015-12-08 13:28:47 +01:00
|
|
|
UserStore.listen(this.onChange);
|
2015-11-04 13:56:43 +01:00
|
|
|
|
2016-01-13 17:24:32 +01:00
|
|
|
this.loadEdition();
|
2015-12-08 13:28:47 +01:00
|
|
|
UserActions.fetchCurrentUser();
|
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-15 13:00:09 +01:00
|
|
|
if (this.props.params.editionId !== nextProps.params.editionId) {
|
2016-01-14 13:20:45 +01:00
|
|
|
EditionActions.flushEdition();
|
2016-01-13 17:24:32 +01:00
|
|
|
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-01-15 13:00:09 +01:00
|
|
|
const { err: editionErr } = this.state.editionMeta;
|
|
|
|
|
2016-01-13 17:24:32 +01:00
|
|
|
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-12-09 13:28:11 +01:00
|
|
|
UserStore.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
|
|
|
|
2015-12-08 13:28:47 +01:00
|
|
|
if(state && state.edition && state.edition.digital_work) {
|
|
|
|
let isEncoding = state.edition.digital_work.isEncoding;
|
|
|
|
if (state.edition.digital_work.mime === 'video' && typeof isEncoding === 'number' && isEncoding !== 100 && !this.state.timerId) {
|
2016-01-13 17:24:32 +01:00
|
|
|
let timerId = window.setInterval(() => EditionActions.fetchEdition(this.props.params.editionId), 10000);
|
2015-12-08 13:28:47 +01:00
|
|
|
this.setState({timerId: timerId});
|
|
|
|
}
|
|
|
|
}
|
2015-06-05 14:22:02 +02:00
|
|
|
},
|
|
|
|
|
2016-01-13 17:24:32 +01:00
|
|
|
loadEdition(editionId = this.props.params.editionId) {
|
|
|
|
EditionActions.fetchEdition(editionId);
|
|
|
|
},
|
|
|
|
|
2015-05-26 10:52:20 +02:00
|
|
|
render() {
|
2015-12-09 13:21:55 +01:00
|
|
|
const { edition, currentUser, coaMeta } = this.state;
|
2015-12-09 15:56:47 +01:00
|
|
|
const { actionPanelButtonListType, furtherDetailsType } = this.props;
|
|
|
|
|
2016-01-14 16:31:19 +01:00
|
|
|
if (edition.id) {
|
2016-01-18 11:37:11 +01:00
|
|
|
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}
|
|
|
|
furtherDetailsType={furtherDetailsType}
|
2015-12-09 11:41:46 +01:00
|
|
|
edition={edition}
|
|
|
|
coaError={coaMeta.err}
|
|
|
|
currentUser={currentUser}
|
2016-01-13 17:24:32 +01: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;
|