diff options
author | Frederick Yin <fkfd@fkfd.me> | 2023-07-24 15:12:19 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2023-07-24 15:12:19 +0800 |
commit | f1af2a3b81a308c19ed96b37cdc72e06b92ad24e (patch) | |
tree | 2f36e10a4c4bb80a2420930adc835edf99a28af3 /contents/ui | |
parent | c21c52cadee77f6f60cc08300717a90ac985082d (diff) |
Include pagination parameter only when necessary
Diffstat (limited to 'contents/ui')
-rw-r--r-- | contents/ui/main.qml | 11 |
1 files changed, 8 insertions, 3 deletions
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) }) } |