{"size": 1802, "ext": "js", "max_stars_repo_path": "src/components/dashboard/Dashboard.js", "max_stars_repo_name": "vinhvn/projects-app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/dashboard/Dashboard.js", "max_issues_repo_name": "vinhvn/projects-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/dashboard/Dashboard.js", "max_forks_repo_name": "vinhvn/projects-app", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.7636363636, "max_line_length": 76, "alphanum_fraction": 0.5332963374}
import React, { Component } from 'react';
import Notifications from './Notifications';
import ProjectList from '../projects/ProjectList';
import { connect } from 'react-redux';
import { firestoreConnect } from 'react-redux-firebase';
import { compose } from 'redux';
import { Redirect } from 'react-router-dom';

class Dashboard extends Component {
    render() {
        const { projects, notifications, auth } = this.props;
        if (!auth.uid) return <Redirect to={'/login'} />;
        const projectList =
            projects === undefined || projects.length === 0 ? (
                <div className='card z-depth-0'>
                    <div className={'card-content grey-text text-darken-3'}>
                        <h6 className={'center'}>No projects found.</h6>
                    </div>
                </div>
            ) : (
                <ProjectList projects={projects} />
            );
        return (
            <div className='dashboard container'>
                <div className='row'>
                    <div className='col s12 m6'>{projectList}</div>
                    <div className='col s12 m5 offset-m1'>
                        <Notifications notifications={notifications} />
                    </div>
                </div>
            </div>
        );
    }
}

const mapStateToProps = (state) => {
    return {
        projects: state.firestore.ordered.projects,
        notifications: state.firestore.ordered.notifications,
        auth: state.firebase.auth,
    };
};

export default compose(
    connect(mapStateToProps),
    firestoreConnect([
        { collection: 'projects', orderBy: ['createdAt', 'desc'] },
        {
            collection: 'notifications',
            limit: 3,
            orderBy: ['time', 'desc'],
        },
    ])
)(Dashboard);
