1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

Redirect if no artworks are found

This commit is contained in:
vrde 2015-07-13 22:05:16 +02:00
parent 1aa2863b80
commit 5ea6095f6a
3 changed files with 26 additions and 5 deletions

View File

@ -20,7 +20,7 @@ import AppConstants from '../constants/application_constants';
let PieceList = React.createClass({
propTypes: {
query: React.PropTypes.object
redirectTo: React.PropTypes.string
},
mixins: [Router.Navigation, Router.State],
@ -30,7 +30,7 @@ let PieceList = React.createClass({
},
componentDidMount() {
let page = this.props.query.page || 1;
let page = this.getQuery().page || 1;
PieceListStore.listen(this.onChange);
if (this.state.pieceList.length === 0){
PieceListActions.fetchPieceList(page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc)
@ -38,6 +38,12 @@ let PieceList = React.createClass({
}
},
componentDidUpdate() {
if (this.props.redirectTo && this.state.pieceListCount === 0) {
this.transitionTo(this.props.redirectTo);
}
},
componentWillUnmount() {
PieceListStore.unlisten(this.onChange);
},
@ -67,7 +73,7 @@ let PieceList = React.createClass({
},
getPagination() {
let currentPage = parseInt(this.props.query.page, 10) || 1;
let currentPage = parseInt(this.getQuery().page, 10) || 1;
let totalPages = Math.ceil(this.state.pieceListCount / this.state.pageSize);
if (this.state.pieceListCount > 10) {

View File

@ -0,0 +1,15 @@
'use strict';
import React from 'react';
import PieceList from '../../../piece_list';
let PrizePieceList = React.createClass({
render() {
return (
<PieceList redirectTo="register_piece" />
);
}
});
export default PrizePieceList;

View File

@ -8,7 +8,7 @@ import LoginContainer from './components/login_container';
import SignupContainer from './components/signup_container';
import PasswordResetContainer from '../../../components/password_reset_container';
import RegisterPiece from '../../../components/register_piece';
import PieceList from '../../../components/piece_list';
import PrizePieceList from './components/piece_list';
import App from './app';
import AppConstants from '../../../constants/application_constants';
@ -25,7 +25,7 @@ function getRoutes(commonRoutes) {
<Route name="signup" path="signup" handler={SignupContainer} />
<Route name="password_reset" path="password_reset" handler={PasswordResetContainer} />
<Route name="register_piece" path="register_piece" handler={RegisterPiece} />
<Route name="pieces" path="collection" handler={PieceList} />
<Route name="pieces" path="collection" handler={PrizePieceList} />
</Route>
);
}