summaryrefslogtreecommitdiff
path: root/contents
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-04-09 11:41:58 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-04-09 11:41:58 +0800
commit6606ada36caa0b1562b3a08d10e8e141be1802e1 (patch)
tree25a96e26a4145b856a8b6256dafd8e175edae9c8 /contents
parent5188870ea50dc6d8db56ea003270769bc4ec2011 (diff)
Use separate API endpoints
Diffstat (limited to 'contents')
-rw-r--r--contents/config/main.xml4
-rw-r--r--contents/ui/ActivityView.qml10
-rw-r--r--contents/ui/main.qml55
3 files changed, 36 insertions, 33 deletions
diff --git a/contents/config/main.xml b/contents/config/main.xml
index fd25c00..6d743c8 100644
--- a/contents/config/main.xml
+++ b/contents/config/main.xml
@@ -13,7 +13,7 @@
</entry>
</group>
<group name="Data">
- <entry name="importantActivities" type="StringList">
- </entry>
+ <entry name="importantAnnouncements" type="StringList"></entry>
+ <entry name="importantAssignments" type="StringList"></entry>
</group>
</kcfg>
diff --git a/contents/ui/ActivityView.qml b/contents/ui/ActivityView.qml
index cbbd6f9..e6945f2 100644
--- a/contents/ui/ActivityView.qml
+++ b/contents/ui/ActivityView.qml
@@ -145,7 +145,13 @@ RowLayout {
important = !important
activityLabel.font.bold = important
activityLabel.color = important ? PlasmaCore.Theme.negativeTextColor : PlasmaCore.Theme.textColor
- let importantActivities = plasmoid.configuration.importantActivities
+
+ const configKeys = {
+ announcement: "importantAnnouncements",
+ assignment: "importantAssignments",
+ }
+
+ let importantActivities = plasmoid.configuration[configKeys[type]]
if (important) {
if (!importantActivities.includes(activityId)) {
importantActivities.push(activityId)
@@ -155,7 +161,7 @@ RowLayout {
importantActivities.splice(importantActivities.indexOf(activityId), 1)
}
// save config
- plasmoid.configuration.importantActivities = importantActivities
+ plasmoid.configuration[configKeys[type]] = importantActivities
}
}
}
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()),
+ })
})
})
}