From 41e83ceb0875f1ead3ff49452a4f6546bbf065d9 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Sat, 9 Apr 2022 12:13:39 +0800 Subject: Display important activities on top --- contents/ui/main.qml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'contents/ui') diff --git a/contents/ui/main.qml b/contents/ui/main.qml index 9805065..468f449 100644 --- a/contents/ui/main.qml +++ b/contents/ui/main.qml @@ -49,23 +49,31 @@ Item { announcementsModel.clear() assignmentsModel.clear() + let importantCount = {announcements: 0, assignments: 0} + for (let course of courses) { callApi(`/announcements?context_codes[]=course_${course[0]}`, 10, announcements => { announcements.forEach(announcement => { - announcementsModel.append({ + const info = { type: "announcement", activityId: announcement.id, course: course[1], title: announcement.title, url: announcement.html_url, important: plasmoid.configuration.importantAnnouncements.includes(announcement.id.toString()), - }) + } + + if (info.important) { + announcementsModel.insert(importantCount.announcements++, info) // place above unimportant ones + } else { + announcementsModel.append(info) + } }) }) callApi(`/courses/${course[0]}/assignments`, 10, assignments => { assignments.forEach(assignment => { - assignmentsModel.append({ + const info = { type: "assignment", activityId: assignment.id, course: course[1], @@ -73,7 +81,13 @@ Item { dueAt: assignment.due_at, url: assignment.html_url, important: plasmoid.configuration.importantAssignments.includes(assignment.id.toString()), - }) + } + + if (info.important) { + assignmentsModel.insert(importantCount.assignments++, info) + } else { + assignmentsModel.append(info) + } }) }) } -- cgit v1.2.3