utilities.ts 575 Bytes
Newer Older
Zac Wood's avatar
Zac Wood committed
1 2 3
import * as FileSaver from 'file-saver';

export const ENDPOINTS = {
Zac Wood's avatar
Zac Wood committed
4
    generateCalendar: 'http://localhost:3000/api/generate',
Zac Wood's avatar
Zac Wood committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
};

export function postData(endpoint: string, data: any): Promise<Response> {
    return fetch(endpoint, {
        method: 'POST',
        body: JSON.stringify(data),
        headers: {
            'Content-Type': 'application/json',
        },
    });
}

export function downloadCalendar(calendarText: string) {
    const blob = new Blob([calendarText], { type: 'text/plain;charset=utf-8' });
    FileSaver.saveAs(blob, 'GMU Fall 2018.ics');
}