-
Notifications
You must be signed in to change notification settings - Fork 38
/
data.js
36 lines (31 loc) · 905 Bytes
/
data.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
import Cookie from 'js-cookie'
const handleError = res => {
if (!res.ok) {
// Return the statusText or if it's empty just return the status
// This is to preserve existing behavior where statusText was returned but isn't always available
throw Error(res.statusText || res.status.toString())
}
return res
}
const defaultFetchOptions = {
headers: {
Accept: 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'X-CSRFToken': Cookie.get('csrftoken')
},
credentials: 'include'
}
const getCurrentWeek = assignmentData => {
const currentWeekObject = assignmentData
.find(x => x.due_date_items[0].assignment_items[0].current_week)
return currentWeekObject
? currentWeekObject.week
: null
}
const loadedWithoutError = (loading, error) => !loading && !error
export {
handleError,
defaultFetchOptions,
getCurrentWeek,
loadedWithoutError
}