Schedule.tsx 1.08 KB
Newer Older
David Haynes's avatar
David Haynes committed
1
import { connect } from 'react-redux';
David Haynes's avatar
David Haynes committed
2
import { removeCourseSection } from '../actions/schedule/schedule.actions';
David Haynes's avatar
David Haynes committed
3
4
import ScheduleRoot from '../components/ScheduleRoot';
import { State } from '../reducers';
5
6
7
import CourseSection from '../util/CourseSection';
import ApiService from '../util/ApiService';
import { downloadFile } from '../util/utilities';
David Haynes's avatar
David Haynes committed
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Takes the current Redux state and returns objects which will be
// passed to the component as Props
const mapStateToProps = (state: State) => {
    const crns = state.schedule ? state.schedule.map(section => section.crn) : [];
    return {
        schedule: state.schedule,
        generateCalendarUrl: () => ApiService.generateCalendarUrl(crns),
        openCalendarAsWebcal: () => ApiService.openCalendarAsWebcal(crns),
        downloadIcs: async () => {
            const icsText = await ApiService.fetchICal(crns);
            downloadFile(icsText, 'GMU Fall 2018.ics');
        },
    };
};
David Haynes's avatar
David Haynes committed
23

24
// Pass mapStateToProps and other values to the component's props
David Haynes's avatar
David Haynes committed
25
26
export default connect(
    mapStateToProps,
David Haynes's avatar
David Haynes committed
27
    { removeCourseSection }
David Haynes's avatar
David Haynes committed
28
)(ScheduleRoot);