From f1af2a3b81a308c19ed96b37cdc72e06b92ad24e Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Mon, 24 Jul 2023 15:12:19 +0800 Subject: Include pagination parameter only when necessary --- contents/ui/main.qml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'contents/ui') diff --git a/contents/ui/main.qml b/contents/ui/main.qml index 0bff9ad..a70cc74 100644 --- a/contents/ui/main.qml +++ b/contents/ui/main.qml @@ -18,9 +18,14 @@ Item { readonly property string oauth2Token: plasmoid.configuration.oauth2Token readonly property string authHeader: `Bearer ${oauth2Token}` - function callApi(path, amount, callback) { + function callApi(path, perPage, callback) { let xhr = new XMLHttpRequest() - xhr.open("GET", `${apiEndpoint}${path}${path.includes("?") ? "&" : "?"}per_page=${amount}`) + let apiUrl = `${apiEndpoint}${path}` + if (perPage >= 1) { + // add pagination parameter + apiUrl += `${path.includes("?") ? "&" : "?"}per_page=${perPage}` + } + xhr.open("GET", apiUrl) xhr.setRequestHeader("Authorization", authHeader) xhr.onload = () => { if (xhr.status == 200) { @@ -52,7 +57,7 @@ Item { const showSubmittedAssignments = plasmoid.configuration.showSubmittedAssignments // we need user id to check submission status - callApi("/users/self", 1, user => { + callApi("/users/self", 0, user => { syncCourses(courses, showSubmittedAssignments, user.id) }) } -- cgit v1.2.3