summaryrefslogtreecommitdiff
path: root/contents/ui/main.qml
diff options
context:
space:
mode:
Diffstat (limited to 'contents/ui/main.qml')
-rw-r--r--contents/ui/main.qml55
1 files changed, 26 insertions, 29 deletions
diff --git a/contents/ui/main.qml b/contents/ui/main.qml
index 38168d6..17c330e 100644
--- a/contents/ui/main.qml
+++ b/contents/ui/main.qml
@@ -20,7 +20,7 @@ Item {
function callApi(path, amount, callback) {
let xhr = new XMLHttpRequest()
- xhr.open("GET", `${apiEndpoint}${path}` + (amount ? `?per_page=${amount}` : ""))
+ xhr.open("GET", `${apiEndpoint}${path}${path.includes("?") ? "&" : "?"}per_page=${amount}`)
xhr.setRequestHeader("Authorization", authHeader)
xhr.onload = () => {
if (xhr.status == 200) {
@@ -40,7 +40,7 @@ Item {
}
function syncCanvas() {
- let courses = plasmoid.configuration.courses.split("\n").map(
+ const courses = plasmoid.configuration.courses.split("\n").map(
// each line in the "courses" config consists of
// a numeric course id, a space, and a course code
line => { return line.split(" ", 2) }
@@ -50,33 +50,30 @@ Item {
assignmentsModel.clear()
for (let course of courses) {
- callApi(`/courses/${course[0]}/activity_stream`, 10, activityStream => {
- // Get activity stream for each course
- activityStream.forEach(activity => {
- let important = plasmoid.configuration.importantActivities.includes(
- activity.id.toString()
- )
-
- if (activity.type == "Announcement") {
- announcementsModel.append({
- type: "announcement",
- activityId: activity.id,
- course: course[1],
- title: activity.title,
- url: activity.html_url,
- important,
- })
- } else if (activity.type == "Submission") {
- assignmentsModel.append({
- type: "assignment",
- activityId: activity.id,
- course: course[1],
- title: activity.title,
- dueAt: activity.assignment.due_at,
- url: activity.html_url,
- important,
- })
- }
+ callApi(`/announcements?context_codes[]=course_${course[0]}`, 10, announcements => {
+ announcements.forEach(announcement => {
+ announcementsModel.append({
+ type: "announcement",
+ activityId: announcement.id,
+ course: course[1],
+ title: announcement.title,
+ url: announcement.html_url,
+ important: plasmoid.configuration.importantAnnouncements.includes(announcement.id.toString()),
+ })
+ })
+ })
+
+ callApi(`/courses/${course[0]}/assignments`, 10, assignments => {
+ assignments.forEach(assignment => {
+ assignmentsModel.append({
+ type: "assignment",
+ activityId: assignment.id,
+ course: course[1],
+ title: assignment.name,
+ dueAt: assignment.due_at,
+ url: assignment.html_url,
+ important: plasmoid.configuration.importantAssignments.includes(assignment.id.toString()),
+ })
})
})
}