{"size": 1644, "ext": "js", "max_stars_repo_path": "src/components/calendar/Week.js", "max_stars_repo_name": "mlwigdahl/react-calendar-katherine", "max_stars_repo_stars_event_min_datetime": "2016-11-17T00:18:54.000Z", "max_stars_repo_stars_event_max_datetime": "2016-12-13T17:06:54.000Z", "max_issues_repo_path": "src/components/calendar/Week.js", "max_issues_repo_name": "mlwigdahl/react-visual-calendar", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/calendar/Week.js", "max_forks_repo_name": "mlwigdahl/react-visual-calendar", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.9090909091, "max_line_length": 86, "alphanum_fraction": 0.5590024331}
import React from 'react';
import PropTypes from 'prop-types';

import Day from './Day';

function monthStyle(date) {
    return ({ className: `month-${date.format('MMM')}`.toLowerCase() });
}

function renderDays(curDate, dates, events, weekStart) {
    const days = [];

    for(let i = 0; i < 7; i++) {
        const key = weekStart.format('YYYYMMDD');

        days.push(
            <Day 
                styleObj={monthStyle(weekStart)}
                key={key}
                date={{ day: weekStart.format('MMM DD') }}
                curDate={curDate}
                events={findEvents(dates, events, key)}
            />
        );
        weekStart.add(1, 'day');
    }

    return days;
}

function findEvents(dates, events, date) {
    const targetDate = dates[date];

    return targetDate !== undefined ? 
        targetDate.events
            .reduce((acc, event) => { acc[event] = events[event]; return acc; }, {}) :
        {};
}

function Week({curDate, dates, events, weekStart}) {
    return (
        <div className="week">
            {renderDays(curDate, dates, events, weekStart)}
        </div>
    );
}

Week.propTypes = {
    dates: PropTypes.objectOf(
        PropTypes.shape({
            events: PropTypes.arrayOf(PropTypes.number)
        })
    ).isRequired,
    events: PropTypes.objectOf(
        PropTypes.shape({
            icon: PropTypes.string,
            label: PropTypes.string,
            startTime: PropTypes.string,
            endDate: PropTypes.string,
        })
    ).isRequired,
    curDate: PropTypes.string.isRequired,
    weekStart: PropTypes.object.isRequired,
};

export default Week;