From 07926e1d43dda6e6acb64c691ceefb818da87ba7 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Fri, 21 Jul 2023 14:57:15 +0800 Subject: Fix false submitted bug --- contents/ui/main.qml | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'contents/ui/main.qml') diff --git a/contents/ui/main.qml b/contents/ui/main.qml index 41af62a..da80c38 100644 --- a/contents/ui/main.qml +++ b/contents/ui/main.qml @@ -51,6 +51,13 @@ Item { const showSubmittedAssignments = plasmoid.configuration.showSubmittedAssignments + // we need user id to check submission status + callApi("/users/self", 1, user => { + syncCourses(courses, showSubmittedAssignments, user.id) + }) + } + + function syncCourses(courses, showSubmittedAssignments, userId) { announcementsModel.clear() assignmentsModel.clear() @@ -79,25 +86,27 @@ Item { callApi(`/courses/${course.id}/assignments`, 10, assignments => { assignments.forEach(assignment => { - const info = { - type: "assignment", - activityId: assignment.id, - course: course.code, - title: assignment.name, - dueAt: assignment.due_at, - submitted: assignment.has_submitted_submissions, - url: assignment.html_url, - important: plasmoid.configuration.importantAssignments.includes(assignment.id.toString()), - finished: plasmoid.configuration.finishedAssignments.includes(assignment.id.toString()), - } + callApi(`/courses/${course.id}/assignments/${assignment.id}/submissions/${userId}`, 1, submission => { + const info = { + type: "assignment", + activityId: assignment.id, + course: course.code, + title: assignment.name, + dueAt: assignment.due_at, + submitted: submission.workflow_state != "unsubmitted", + url: assignment.html_url, + important: plasmoid.configuration.importantAssignments.includes(assignment.id.toString()), + finished: plasmoid.configuration.finishedAssignments.includes(assignment.id.toString()), + } - if (!info.submitted || showSubmittedAssignments) { - if (info.important) { - assignmentsModel.insert(importantCount.assignments++, info) - } else { - assignmentsModel.append(info) + if (!info.submitted || showSubmittedAssignments) { + if (info.important) { + assignmentsModel.insert(importantCount.assignments++, info) + } else { + assignmentsModel.append(info) + } } - } + }) }) }) } -- cgit v1.2.3