search.actions.ts 788 Bytes
Newer Older
Andrew Hrdy's avatar
Andrew Hrdy committed
1
import { Section } from '../../ts/section';
David Haynes's avatar
David Haynes committed
2
import { SET_SEARCH_SECTIONS } from './search.action-types';
Andrew Hrdy's avatar
Andrew Hrdy committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

export interface SearchAction {
    type: string;
    sections: Section[];
}

export const searchSections = (crn: string) => async (dispatch: any) => {
    const response = await fetch(`http://localhost:3000/api/search?crn=${crn}`);
    const object = await response.json();

    const section: Section = {
        id: object.id,
        name: object.name,
        title: object.title,
        crn: object.crn,
        instructor: object.instructor,
        location: object.location,
        days: object.days,
        startTime: object.start_time,
        endTime: object.end_time,
    };

    dispatch({
        type: SET_SEARCH_SECTIONS,
David Haynes's avatar
David Haynes committed
27
        sections: [section],
Andrew Hrdy's avatar
Andrew Hrdy committed
28
    });
David Haynes's avatar
David Haynes committed
29
};