mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
feat: add loading animations to lessons on home page
This commit is contained in:
@@ -1,26 +1,21 @@
|
|||||||
import { delay } from "../delay";
|
|
||||||
import stringToHTML from "../stringToHTML";
|
|
||||||
import { animate, stagger } from "motion";
|
import { animate, stagger } from "motion";
|
||||||
import { settingsState } from "../listeners/SettingsState";
|
|
||||||
|
|
||||||
import { addShortcuts } from "../Adders/AddShortcuts";
|
|
||||||
|
|
||||||
import browser from "webextension-polyfill";
|
import browser from "webextension-polyfill";
|
||||||
import { GetThresholdOfColor } from "@/seqta/ui/colors/getThresholdColour";
|
|
||||||
import LogoLight from "@/resources/icons/betterseqta-light-icon.png";
|
import LogoLight from "@/resources/icons/betterseqta-light-icon.png";
|
||||||
import { CreateCustomShortcutDiv } from "@/seqta/utils/CreateEnable/CreateCustomShortcutDiv";
|
|
||||||
|
|
||||||
import assessmentsicon from "@/seqta/icons/assessmentsIcon";
|
import assessmentsicon from "@/seqta/icons/assessmentsIcon";
|
||||||
import coursesicon from "@/seqta/icons/coursesIcon";
|
import coursesicon from "@/seqta/icons/coursesIcon";
|
||||||
|
import { GetThresholdOfColor } from "@/seqta/ui/colors/getThresholdColour";
|
||||||
import { FilterUpcomingAssessments } from "@/seqta/utils/FilterUpcomingAssessments";
|
import { addShortcuts } from "../Adders/AddShortcuts";
|
||||||
|
|
||||||
import { CreateElement } from "@/seqta/utils/CreateEnable/CreateElement";
|
|
||||||
|
|
||||||
import { convertTo12HourFormat } from "../convertTo12HourFormat";
|
import { convertTo12HourFormat } from "../convertTo12HourFormat";
|
||||||
|
import { delay } from "../delay";
|
||||||
|
import { settingsState } from "../listeners/SettingsState";
|
||||||
|
import stringToHTML from "../stringToHTML";
|
||||||
|
import { CreateCustomShortcutDiv } from "@/seqta/utils/CreateEnable/CreateCustomShortcutDiv";
|
||||||
|
import { CreateElement } from "@/seqta/utils/CreateEnable/CreateElement";
|
||||||
|
import { FilterUpcomingAssessments } from "@/seqta/utils/FilterUpcomingAssessments";
|
||||||
|
|
||||||
let LessonInterval: any;
|
let LessonInterval: any;
|
||||||
let currentSelectedDate = new Date();
|
let currentSelectedDate = new Date();
|
||||||
|
let loadingTimeout: any;
|
||||||
|
|
||||||
export async function loadHomePage() {
|
export async function loadHomePage() {
|
||||||
console.info("[BetterSEQTA+] Started Loading Home Page");
|
console.info("[BetterSEQTA+] Started Loading Home Page");
|
||||||
@@ -276,6 +271,20 @@ function setupTimetableListeners() {
|
|||||||
const timetableForward = document.getElementById("home-timetable-forward");
|
const timetableForward = document.getElementById("home-timetable-forward");
|
||||||
|
|
||||||
function changeTimetable(value: number) {
|
function changeTimetable(value: number) {
|
||||||
|
// Clear any existing loading timeout
|
||||||
|
if (loadingTimeout) {
|
||||||
|
clearTimeout(loadingTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only show loading state after 200ms to avoid flicker on fast connections
|
||||||
|
loadingTimeout = setTimeout(() => {
|
||||||
|
const dayContainer = document.getElementById("day-container");
|
||||||
|
if (dayContainer) {
|
||||||
|
dayContainer.classList.add("loading");
|
||||||
|
dayContainer.innerHTML = "";
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
|
|
||||||
currentSelectedDate.setDate(currentSelectedDate.getDate() + value);
|
currentSelectedDate.setDate(currentSelectedDate.getDate() + value);
|
||||||
const formattedDate = formatDate(currentSelectedDate);
|
const formattedDate = formatDate(currentSelectedDate);
|
||||||
callHomeTimetable(formattedDate, true);
|
callHomeTimetable(formattedDate, true);
|
||||||
@@ -455,9 +464,17 @@ function callHomeTimetable(date: string, change?: any) {
|
|||||||
xhr.onreadystatechange = function () {
|
xhr.onreadystatechange = function () {
|
||||||
// Once the response is ready
|
// Once the response is ready
|
||||||
if (xhr.readyState === 4) {
|
if (xhr.readyState === 4) {
|
||||||
var serverResponse = JSON.parse(xhr.response);
|
// Clear the loading timeout since we got a response
|
||||||
let lessonArray: Array<any> = [];
|
if (loadingTimeout) {
|
||||||
|
clearTimeout(loadingTimeout);
|
||||||
|
loadingTimeout = null;
|
||||||
|
}
|
||||||
|
|
||||||
const DayContainer = document.getElementById("day-container")!;
|
const DayContainer = document.getElementById("day-container")!;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var serverResponse = JSON.parse(xhr.response);
|
||||||
|
let lessonArray: Array<any> = [];
|
||||||
// If items in response:
|
// If items in response:
|
||||||
if (serverResponse.payload.items.length > 0) {
|
if (serverResponse.payload.items.length > 0) {
|
||||||
if (DayContainer.innerText || change) {
|
if (DayContainer.innerText || change) {
|
||||||
@@ -518,6 +535,9 @@ function callHomeTimetable(date: string, change?: any) {
|
|||||||
DayContainer.append(div.firstChild as HTMLElement);
|
DayContainer.append(div.firstChild as HTMLElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove loading state after lessons are loaded
|
||||||
|
DayContainer.classList.remove("loading");
|
||||||
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
if (currentSelectedDate.getDate() == today.getDate()) {
|
if (currentSelectedDate.getDate() == today.getDate()) {
|
||||||
for (let i = 0; i < lessonArray.length; i++) {
|
for (let i = 0; i < lessonArray.length; i++) {
|
||||||
@@ -539,6 +559,24 @@ function callHomeTimetable(date: string, change?: any) {
|
|||||||
dummyDay.append(img);
|
dummyDay.append(img);
|
||||||
dummyDay.append(text);
|
dummyDay.append(text);
|
||||||
DayContainer.append(dummyDay);
|
DayContainer.append(dummyDay);
|
||||||
|
|
||||||
|
// Remove loading state when no lessons available
|
||||||
|
DayContainer.classList.remove("loading");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading timetable data:", error);
|
||||||
|
// Remove loading state even if there's an error
|
||||||
|
DayContainer.classList.remove("loading");
|
||||||
|
|
||||||
|
// Show error message
|
||||||
|
DayContainer.innerHTML = "";
|
||||||
|
const errorDiv = document.createElement("div");
|
||||||
|
errorDiv.classList.add("day-empty");
|
||||||
|
errorDiv.innerHTML = `
|
||||||
|
<img src="${browser.runtime.getURL(LogoLight)}" />
|
||||||
|
<p>Error loading lessons. Please try again.</p>
|
||||||
|
`;
|
||||||
|
DayContainer.append(errorDiv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user