Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/webpack - Actions, reducers lintable, alerts in progress #805

Merged
merged 22 commits into from
Apr 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2dbe942
fully linted calendar_actions
noahpresler Apr 14, 2017
4624d9c
Merge branch 'refactor/webpack' of https://github.com/rohandas/semest…
noahpresler Apr 14, 2017
09128d1
modal_actions fully linted
noahpresler Apr 14, 2017
338914f
school_actions refactored
noahpresler Apr 14, 2017
14777fa
search_actions linted
noahpresler Apr 14, 2017
b44cc2b
timetable actions linted!
noahpresler Apr 14, 2017
299f43f
fully linted calendar_actions
noahpresler Apr 14, 2017
40f02e0
modal_actions fully linted
noahpresler Apr 14, 2017
3b44c6a
school_actions refactored
noahpresler Apr 14, 2017
6765f5b
search_actions linted
noahpresler Apr 14, 2017
3f55fb7
timetable actions linted!
noahpresler Apr 14, 2017
95a030d
linted user_actions
noahpresler Apr 15, 2017
b6ab8ad
Merge branch 'refactor/webpack' of https://github.com/rohandas/semest…
noahpresler Apr 15, 2017
8b4706b
fix school actions
noahpresler Apr 15, 2017
34acf9d
fix typos in user_actions
noahpresler Apr 15, 2017
09429b3
update colours for lint passing
noahpresler Apr 15, 2017
2db995d
constants lintable
noahpresler Apr 15, 2017
14979dd
lintable reducers 9all of them
noahpresler Apr 16, 2017
afb85c7
Merge branch 'staging' into refactor/webpack
noahpresler Apr 17, 2017
f110ec2
fix a few alerts with PropTypes and FIX DISPATCH BUG FOR SEMESTER set…
noahpresler Apr 17, 2017
5a46ca0
Merge branch 'refactor/webpack' of https://github.com/rohandas/semest…
noahpresler Apr 17, 2017
ab74e1f
use only arrow functions and no store.dispatch
noahpresler Apr 17, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
"jasmine": true
},
"globals": {
"_": true,
"allSemesters": true,
"sharedTimetable": true,
"sharedCourse": true,
Expand Down
238 changes: 118 additions & 120 deletions static/js/redux/actions/calendar_actions.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ical from 'ical-generator';
import FileSaver from 'browser-filesaver';
import {
getAddTTtoGCalEndpoint,
getLogFinalExamViewEndpoint,
Expand All @@ -7,9 +9,7 @@ import {
import { FULL_WEEK_LIST } from '../constants/constants';
import { getActiveTimetable } from './user_actions';
import { store } from '../init';
import ical from 'ical-generator';
import { getCourseShareLink } from '../helpers/timetable_helpers';
import FileSaver from 'browser-filesaver';
import * as ActionTypes from '../constants/actionTypes';

const DAY_MAP = {
Expand All @@ -22,145 +22,143 @@ const DAY_MAP = {
U: 'su',
};

function getNextDayOfWeek(date, dayOfWeek) {
dayOfWeek = FULL_WEEK_LIST.indexOf(dayOfWeek);
export const getNextDayOfWeek = (date, dayOfWeek) => {
const dayIndex = FULL_WEEK_LIST.indexOf(dayOfWeek);
const resultDate = new Date(date.getTime());
resultDate.setDate(date.getDate() + (7 + dayOfWeek - date.getDay()) % 7);
resultDate.setDate(date.getDate() + ((7 + (dayIndex - date.getDay())) % 7));
return resultDate;
}
};

function receiveShareLink(dispatch, shareLink) {
export const receiveShareLink = shareLink => (dispatch) => {
dispatch({
type: ActionTypes.RECEIVE_SHARE_TIMETABLE_LINK,
shareLink,
});
}
};

export const logFinalExamView = () => (dispatch) => {
export const logFinalExamView = () => {
fetch(getLogFinalExamViewEndpoint(), {
method: 'POST',
credentials: 'include',
});
};

export function fetchShareTimetableLink() {
return (dispatch) => {
const state = store.getState();
const semester = allSemesters[state.semesterIndex];
const timetableState = state.timetables;
const { shareLink, shareLinkValid } = state.calendar;
dispatch({
type: ActionTypes.REQUEST_SHARE_TIMETABLE_LINK,
});
if (shareLinkValid) {
receiveShareLink(store.dispatch, shareLink);
return;
}
fetch(getRequestShareTimetableLinkEndpoint(), {
export const fetchShareTimetableLink = () => (dispatch) => {
const state = store.getState();
const semester = allSemesters[state.semesterIndex];
const timetableState = state.timetables;
const { shareLink, shareLinkValid } = state.calendar;
dispatch({
type: ActionTypes.REQUEST_SHARE_TIMETABLE_LINK,
});
if (shareLinkValid) {
receiveShareLink(shareLink);
return;
}
fetch(getRequestShareTimetableLinkEndpoint(), {
method: 'POST',
body: JSON.stringify({
timetable: getActiveTimetable(timetableState),
semester,
}),
credentials: 'include',
})
.then(response => response.json())
.then((ref) => {
dispatch(receiveShareLink(`${window.location.href.split('/')[2]}/share/${ref.link}`));
});
};

export const addTTtoGCal = () => (dispatch) => {
gcalCallback = false;
let state = store.getState();
const timetableState = state.timetables;

// Wait for timetable to load
if (gcalCallback) {
do {
state = store.getState();
} while (state.timetables.items.length <= 0);
}

if (!state.saveCalendarModal.isUploading && !state.saveCalendarModal.hasUploaded) {
dispatch({ type: ActionTypes.UPLOAD_CALENDAR });
fetch(getAddTTtoGCalEndpoint(), {
method: 'POST',
body: JSON.stringify({
timetable: getActiveTimetable(timetableState),
semester,
}),
credentials: 'include',
})
.then(response => response.json())
.then((ref) => {
receiveShareLink(store.dispatch,
`${window.location.href.split('/')[2]}/share/${ref.link}`);
});
};
}

export function addTTtoGCal() {
return (dispatch) => {
gcalCallback = false;
const state = store.getState();
const timetableState = state.timetables;
// Wait for timetable to load
if (gcalCallback) {
while (state.timetables.items.length <= 0) {
}
}
if (!state.saveCalendarModal.isUploading && !state.saveCalendarModal.hasUploaded) {
dispatch({ type: ActionTypes.UPLOAD_CALENDAR });
fetch(getAddTTtoGCalEndpoint(), {
method: 'POST',
body: JSON.stringify({
timetable: getActiveTimetable(timetableState),
}),
credentials: 'include',
})
.then(response => response.json())
.then((json) => {
dispatch({ type: ActionTypes.CALENDAR_UPLOADED });
});
.then(response => response.json())
.then(() => {
dispatch({ type: ActionTypes.CALENDAR_UPLOADED });
});
}
};

export const createICalFromTimetable = () => (dispatch) => {
const state = store.getState();
if (!state.saveCalendarModal.isDownloading && !state.saveCalendarModal.hasDownloaded) {
dispatch({ type: ActionTypes.DOWNLOAD_CALENDAR });
const cal = ical({ domain: 'https://semester.ly', name: 'My Semester Schedule' });
const tt = getActiveTimetable(state.timetables);

// TODO - MUST BE REFACTORED AFTER CODED IN TO CONFIG
let semStart = new Date();
let semEnd = new Date();
const semester = allSemesters[state.semesterIndex];

if (semester.name === 'Fall') {
// ignore year, year is set to current year
semStart = new Date(`August 30 ${semester.year} 00:00:00`);
semEnd = new Date(`December 20 ${semester.year} 00:00:00`);
} else {
// ignore year, year is set to current year
semStart = new Date(`January 30 ${semester.year} 00:00:00`);
semEnd = new Date(`May 20 ${semester.year} 00:00:00`);
}
};
}

export function createICalFromTimetable(active) {
return (dispatch) => {
const state = store.getState();
if (!state.saveCalendarModal.isDownloading && !state.saveCalendarModal.hasDownloaded) {
dispatch({ type: ActionTypes.DOWNLOAD_CALENDAR });
const cal = ical({ domain: 'https://semester.ly', name: 'My Semester Schedule' });
const tt = getActiveTimetable(state.timetables);

// TODO - MUST BE REFACTORED AFTER CODED IN TO CONFIG
let sem_start = new Date();
let sem_end = new Date();
const semester = allSemesters[state.semesterIndex];
if (semester.name == 'Fall') {
// ignore year, year is set to current year
sem_start = new Date(`August 30 ${semester.year} 00:00:00`);
sem_end = new Date(`December 20 ${semester.year} 00:00:00`);
} else {
// ignore year, year is set to current year
sem_start = new Date(`January 30 ${semester.year} 00:00:00`);
sem_end = new Date(`May 20 ${semester.year} 00:00:00`);
}
sem_start.setYear(new Date().getFullYear());
sem_end.setYear(new Date().getFullYear());

for (let c_idx = 0; c_idx < tt.courses.length; c_idx++) {
for (let slot_idx = 0; slot_idx < tt.courses[c_idx].slots.length; slot_idx++) {
const course = tt.courses[c_idx];
const slot = course.slots[slot_idx];
const instructors = slot.instructors && slot.instructors.length > 0 ? `Taught by: ${slot.instructors}\n` : '';
const start = getNextDayOfWeek(sem_start, slot.day);
const end = getNextDayOfWeek(sem_start, slot.day);
const until = getNextDayOfWeek(sem_end, slot.day);

let times = slot.time_start.split(':');
start.setHours(parseInt(times[0]), parseInt(times[1]));
times = slot.time_end.split(':');
end.setHours(parseInt(times[0]), parseInt(times[1]));
const description = course.description ? course.description : '';

const event = cal.createEvent({
start,
end,
summary: `${slot.name} ${slot.code}${slot.meeting_section}`,
description: `${slot.code + slot.meeting_section}\n${instructors}${description}`,
location: slot.location,
url: getCourseShareLink(slot.code),
});

event.repeating({
freq: 'WEEKLY',
byDay: DAY_MAP[slot.day],
until,
});
}
semStart.setYear(new Date().getFullYear());
semEnd.setYear(new Date().getFullYear());

for (let cIdx = 0; cIdx < tt.courses.length; cIdx++) {
for (let slotIdx = 0; slotIdx < tt.courses[cIdx].slots.length; slotIdx++) {
const course = tt.courses[cIdx];
const slot = course.slots[slotIdx];
const instructors = slot.instructors && slot.instructors.length > 0 ? `Taught by: ${slot.instructors}\n` : '';
const start = getNextDayOfWeek(semStart, slot.day);
const end = getNextDayOfWeek(semStart, slot.day);
const until = getNextDayOfWeek(semEnd, slot.day);

let times = slot.time_start.split(':');
start.setHours(parseInt(times[0], 10), parseInt(times[1], 10));
times = slot.time_end.split(':');
end.setHours(parseInt(times[0], 10), parseInt(times[1], 10));
const description = course.description ? course.description : '';

const event = cal.createEvent({
start,
end,
summary: `${slot.name} ${slot.code}${slot.meeting_section}`,
description: `${slot.code + slot.meeting_section}\n${instructors}${description}`,
location: slot.location,
url: getCourseShareLink(slot.code),
});

event.repeating({
freq: 'WEEKLY',
byDay: DAY_MAP[slot.day],
until,
});
}
const file = new Blob([cal.toString()], { type: 'data:text/calendar;charset=utf8,' });
FileSaver.saveAs(file, 'my_semester.ics');
fetch(getLogiCalEndpoint(), {
method: 'POST',
credentials: 'include',
});
dispatch({ type: ActionTypes.CALENDAR_DOWNLOADED });
}
};
}
const file = new Blob([cal.toString()], { type: 'data:text/calendar;charset=utf8,' });
FileSaver.saveAs(file, 'my_semester.ics');
fetch(getLogiCalEndpoint(), {
method: 'POST',
credentials: 'include',
});
dispatch({ type: ActionTypes.CALENDAR_DOWNLOADED });
}
};
Loading