1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01: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 {
constructor() {
this.generateActions(
'updateEdition'
'updateEdition',
'editionFailed'
);
}
@ -18,6 +19,7 @@ class EditionActions {
})
.catch((err) => {
console.logGlobal(err);
this.actions.editionFailed(err.json);
});
}
}

View File

@ -1,6 +1,7 @@
'use strict';
import React from 'react';
import { History } from 'react-router';
import EditionActions from '../../actions/edition_actions';
import EditionStore from '../../stores/edition_store';
@ -15,26 +16,23 @@ import AppConstants from '../../constants/application_constants';
*/
let EditionContainer = React.createClass({
propTypes: {
location: React.PropTypes.object
location: React.PropTypes.object,
params: React.PropTypes.object
},
mixins: [History],
getInitialState() {
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() {
// 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);
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() {
// 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);
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() {
EditionActions.fetchOne(this.props.params.editionId);

View File

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

View File

@ -40,6 +40,15 @@ class Requests {
reject(error);
} else if(body && 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 {
resolve(body);
}