search.actions.ts 847 Bytes
Newer Older
1
import { Section } from '../../util/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

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();

13
14
15
16
17
18
19
20
21
22
23
24
25
    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,
        },
    ];
Andrew Hrdy's avatar
Andrew Hrdy committed
26
27
28

    dispatch({
        type: SET_SEARCH_SECTIONS,
29
        sections: section,
Andrew Hrdy's avatar
Andrew Hrdy committed
30
    });
David Haynes's avatar
David Haynes committed
31
};