-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsession_manager.js
68 lines (57 loc) · 1.61 KB
/
session_manager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import Cookies from 'js-cookie'
export function loadCookieData() {
let courses = Cookies.get('courses')
if(!courses) {
return
}
courses = JSON.parse(courses)
for(const c of courses) {
const course = {
data: window.data[c.id],
label: c.id,
value: c.id
}
window.store.dispatch({
type: 'ADD_COURSE',
course: course,
id: c.id,
selected: c.selected
})
if(!c.unselectedSections) {
continue;
}
for(const section_id of c.unselectedSections) {
window.store.dispatch({
type: 'TOGGLE_SECTION',
course_id: c.id,
section_id: section_id
})
}
}
}
function getUnselectedSections(course) {
let out = []
let sections = course.data.sections
for(const key in sections) {
let section_types = sections[key]
for(let section_type in section_types) {
for(let section of section_types[section_type]) {
if(!section.selected) {
out.push(section['Class Number'])
}
}
}
}
return out
}
export function storeCookieData() {
const state = window.store.getState()
const courses = state.courses.picked
const out = courses.map(course => { return {
id: course.id,
selected: course.selected,
unselectedSections: getUnselectedSections(course.course)
} } )
const str = JSON.stringify(out)
Cookies.set('courses', str, { expires: 365, path: '' });
}