From 5f740256b6bd01dd66fa6e54a5176bd88d68cf6e Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Sat, 9 Apr 2022 16:49:05 +0800 Subject: Show full course code --- contents/ui/main.qml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'contents/ui') diff --git a/contents/ui/main.qml b/contents/ui/main.qml index 8568116..58e3faf 100644 --- a/contents/ui/main.qml +++ b/contents/ui/main.qml @@ -43,7 +43,10 @@ Item { 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) } + line => { + const spaceIndex = line.indexOf(" ") + return {id: line.slice(0, spaceIndex), code: line.slice(spaceIndex + 1)} + } ) const showSubmittedAssignments = plasmoid.configuration.showSubmittedAssignments @@ -54,12 +57,12 @@ Item { let importantCount = {announcements: 0, assignments: 0} for (let course of courses) { - callApi(`/announcements?context_codes[]=course_${course[0]}`, 10, announcements => { + callApi(`/announcements?context_codes[]=course_${course.id}`, 10, announcements => { announcements.forEach(announcement => { const info = { type: "announcement", activityId: announcement.id, - course: course[1], + course: course.code, title: announcement.title, url: announcement.html_url, important: plasmoid.configuration.importantAnnouncements.includes(announcement.id.toString()), @@ -73,12 +76,12 @@ Item { }) }) - callApi(`/courses/${course[0]}/assignments`, 10, assignments => { + callApi(`/courses/${course.id}/assignments`, 10, assignments => { assignments.forEach(assignment => { const info = { type: "assignment", activityId: assignment.id, - course: course[1], + course: course.code, title: assignment.name, dueAt: assignment.due_at, submitted: assignment.has_submitted_submissions, -- cgit v1.2.3