Home Reference Source

application/components/bounce.js

import React from 'react';
import {connect} from 'react-redux';
import {browserHistory} from 'react-router';

import Config from './../config';
import CurrentUser from './../current-user';

import LoadingIndicator from './common/loading-indicator';

import {contentFetchOne} from './../redux/actions/content-actions';

class Bounce extends React.Component {
    constructor(props) {
        super(props);

        if (this.props.router && this.props.router.location.query && this.props.router.location.query.type) {
            this.handleRedirectByType(
                this.props.router.location.query.type,
                this.props.params.id
            );
        } else if (this.props.router && this.props.router.location.query.next) {
            this.handleRedirectTo(
                this.props.router.location.query.next
            );
        } else if (this.props.params && this.props.params.id) {
            this.props.dispatch(contentFetchOne(this.props.params.id))
                .then((content) => {
                    this.handleRedirect(content);
                });
        }
    }

    handleRedirect(content) {
        let linkLocation = '/ceo/content/' + content.get('uuid');
        if (content.get('attachment') && content.get('attachment').get('type') == 'gallery') {
            linkLocation = '/ceo/container/' + content.get('container').get('uuid');
        }

        browserHistory.push(linkLocation);
        _ceoScrollTop();
    }

    handleRedirectTo(loc) {
        browserHistory.push('/ceo/' + loc);
        _ceoScrollTop();
    }

    handleRedirectByType(type, id) {
        let linkLocation = '/ceo/';
        switch (type) {
            case 'container':
                linkLocation += 'container/';
                break;
            case 'assignment':
                linkLocation += 'assignment/';
                break;
        }

        linkLocation += id;

        browserHistory.push(linkLocation);
        _ceoScrollTop();
    }

    render() {
        return (
            <div className="admin-root">
                <LoadingIndicator />
            </div>
        );
    }
}

export default connect()(Bounce);