1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 13:41:57 +02:00

add 404 routine to EditionContainer

This commit is contained in:
Tim Daubenschütz 2015-10-19 15:29:57 +02:00
parent 5a35e40a76
commit 23b7ebd776
4 changed files with 50 additions and 19 deletions

View File

@ -7,7 +7,8 @@ import EditionFetcher from '../fetchers/edition_fetcher';
class EditionActions { class EditionActions {
constructor() { constructor() {
this.generateActions( this.generateActions(
'updateEdition' 'updateEdition',
'editionFailed'
); );
} }
@ -18,6 +19,7 @@ class EditionActions {
}) })
.catch((err) => { .catch((err) => {
console.logGlobal(err); console.logGlobal(err);
this.actions.editionFailed(err.json);
}); });
} }
} }

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
import React from 'react'; import React from 'react';
import { History } from 'react-router';
import EditionActions from '../../actions/edition_actions'; import EditionActions from '../../actions/edition_actions';
import EditionStore from '../../stores/edition_store'; import EditionStore from '../../stores/edition_store';
@ -15,26 +16,23 @@ import AppConstants from '../../constants/application_constants';
*/ */
let EditionContainer = React.createClass({ let EditionContainer = React.createClass({
propTypes: { propTypes: {
location: React.PropTypes.object location: React.PropTypes.object,
params: React.PropTypes.object
}, },
mixins: [History],
getInitialState() { getInitialState() {
return EditionStore.getState(); return EditionStore.getState();
}, },
onChange(state) {
this.setState(state);
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) {
let timerId = window.setInterval(() => EditionActions.fetchOne(this.props.params.editionId), 10000);
this.setState({timerId: timerId});
}
},
componentDidMount() { componentDidMount() {
// Every time we're entering 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({});
EditionStore.listen(this.onChange); EditionStore.listen(this.onChange);
EditionActions.fetchOne(this.props.params.editionId); EditionActions.fetchOne(this.props.params.editionId);
}, },
@ -48,16 +46,32 @@ let EditionContainer = React.createClass({
} }
}, },
componentDidUpdate() {
const { editionError } = this.state;
if(editionError && editionError.status === 404) {
// Even though the /404 path doesn't really exist,
// we can still redirect there and the page will show up
this.history.pushState(null, '/404');
}
},
componentWillUnmount() { componentWillUnmount() {
// 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({});
window.clearInterval(this.state.timerId); window.clearInterval(this.state.timerId);
EditionStore.unlisten(this.onChange); EditionStore.unlisten(this.onChange);
}, },
onChange(state) {
this.setState(state);
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) {
let timerId = window.setInterval(() => EditionActions.fetchOne(this.props.params.editionId), 10000);
this.setState({timerId: timerId});
}
},
loadEdition() { loadEdition() {
EditionActions.fetchOne(this.props.params.editionId); EditionActions.fetchOne(this.props.params.editionId);

View File

@ -7,11 +7,17 @@ import EditionActions from '../actions/edition_actions';
class EditionStore { class EditionStore {
constructor() { constructor() {
this.edition = {}; this.edition = {};
this.editionError = null;
this.bindActions(EditionActions); this.bindActions(EditionActions);
} }
onUpdateEdition(edition) { onUpdateEdition(edition) {
this.edition = edition; this.edition = edition;
this.editionError = null;
}
onEditionFailed(error) {
this.editionError = error;
} }
} }

View File

@ -40,6 +40,15 @@ class Requests {
reject(error); reject(error);
} else if(body && body.detail) { } else if(body && body.detail) {
reject(new Error(body.detail)); reject(new Error(body.detail));
} else if(!body.success) {
let error = new Error('Client Request Error');
error.json = {
status: response.status,
statusText: response.status,
type: response.status,
url: response.url
};
reject(error);
} else { } else {
resolve(body); resolve(body);
} }