From 30c5a823d8a426f5dbacfc5179d8319edb0b5b86 Mon Sep 17 00:00:00 2001 From: sethburkart123 Date: Wed, 28 Aug 2024 15:02:09 +1000 Subject: [PATCH] fix: assessments not loading after notices error #150 --- src/SEQTA.ts | 57 +++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/SEQTA.ts b/src/SEQTA.ts index 101430a5..aff5505c 100644 --- a/src/SEQTA.ts +++ b/src/SEQTA.ts @@ -2195,7 +2195,7 @@ export async function loadHomePage() { var Notices = stringToHTML(NoticesStr) // Appends the shortcut container into the home container - document.getElementById('home-container')!.append(Notices.firstChild!) + document.getElementById('home-container')!.append(Notices.firstChild!) // HERE!!! if (settingsState.animations) { animate( @@ -2219,39 +2219,42 @@ export async function loadHomePage() { const response = await GetPrefs.json() - const labelArray = response.payload.filter((item: any) => item.name === 'notices.filters').map((item: any) => item.value)[0].split(' ') + const labelArray = response.payload.filter((item: any) => item.name === 'notices.filters').map((item: any) => item.value) - const xhr2 = new XMLHttpRequest() - xhr2.open( - 'POST', - `${location.origin}/seqta/student/load/notices?`, - true - ) - xhr2.setRequestHeader('Content-Type', 'application/json; charset=utf-8') - - xhr2.onreadystatechange = function () { - if (xhr2.readyState === 4) { - processNotices(xhr2.response, labelArray); - } - }; - - const dateControl = document.querySelector('input[type="date"]') as HTMLInputElement; - xhr2.send(JSON.stringify({ date: dateControl.value })); - - function onInputChange(e: any) { - xhr2.open('POST', `${location.origin}/seqta/student/load/notices?`, true); - xhr2.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); - xhr2.send(JSON.stringify({ date: e.target.value })); - + if (labelArray.length !== 0) { + const labelArray = response.payload.filter((item: any) => item.name === 'notices.filters').map((item: any) => item.value)[0].split(' ') + const xhr2 = new XMLHttpRequest() + xhr2.open( + 'POST', + `${location.origin}/seqta/student/load/notices?`, + true + ) + xhr2.setRequestHeader('Content-Type', 'application/json; charset=utf-8') + xhr2.onreadystatechange = function () { if (xhr2.readyState === 4) { processNotices(xhr2.response, labelArray); } }; + + const dateControl = document.querySelector('input[type="date"]') as HTMLInputElement; + xhr2.send(JSON.stringify({ date: dateControl.value })); + + function onInputChange(e: any) { + xhr2.open('POST', `${location.origin}/seqta/student/load/notices?`, true); + xhr2.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); + xhr2.send(JSON.stringify({ date: e.target.value })); + + xhr2.onreadystatechange = function () { + if (xhr2.readyState === 4) { + processNotices(xhr2.response, labelArray); + } + }; + } + + dateControl.addEventListener('input', onInputChange); } - - dateControl.addEventListener('input', onInputChange); - + if (settingsState.notificationcollector) { enableNotificationCollector() }