mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
feat: add empty state to notices
This commit is contained in:
@@ -125,22 +125,43 @@ export async function loadHomePage() {
|
|||||||
upcomingItems.classList.remove("loading");
|
upcomingItems.classList.remove("loading");
|
||||||
}
|
}
|
||||||
|
|
||||||
const labelArray = prefs.payload
|
const noticesFilterPrefs = prefs.payload.filter(
|
||||||
.filter((item: any) => item.name === "notices.filters")
|
(item: any) => item.name === "notices.filters",
|
||||||
.map((item: any) => item.value);
|
);
|
||||||
|
const labelArray = noticesFilterPrefs.map((item: any) => item.value);
|
||||||
|
|
||||||
if (labelArray.length > 0) {
|
console.info("[BetterSEQTA+] Notices: prefs", {
|
||||||
const noticeContainer = document.getElementById("notice-container");
|
hasNoticesFiltersPref: noticesFilterPrefs.length > 0,
|
||||||
if (noticeContainer) {
|
noticesFilterPrefs,
|
||||||
const dateControl = document.querySelector(
|
labelArrayLength: labelArray.length,
|
||||||
'input[type="date"]',
|
});
|
||||||
) as HTMLInputElement;
|
|
||||||
if (dateControl) {
|
const noticeContainer = document.getElementById("notice-container");
|
||||||
dateControl.value = TodayFormatted;
|
if (!noticeContainer) {
|
||||||
setupNotices(labelArray[0].split(" "), TodayFormatted);
|
console.warn("[BetterSEQTA+] Notices: notice-container element not found");
|
||||||
}
|
} else if (labelArray.length > 0) {
|
||||||
noticeContainer.classList.remove("loading");
|
const dateControl = document.querySelector(
|
||||||
|
'input[type="date"]',
|
||||||
|
) as HTMLInputElement;
|
||||||
|
if (dateControl) {
|
||||||
|
dateControl.value = TodayFormatted;
|
||||||
|
setupNotices(labelArray[0].split(" "), TodayFormatted);
|
||||||
|
} else {
|
||||||
|
console.warn("[BetterSEQTA+] Notices: date input not found, cannot setup notices");
|
||||||
}
|
}
|
||||||
|
noticeContainer.classList.remove("loading");
|
||||||
|
} else {
|
||||||
|
console.info("[BetterSEQTA+] Notices: no notices.filters pref — showing empty state");
|
||||||
|
noticeContainer.classList.remove("loading");
|
||||||
|
noticeContainer.innerHTML = "";
|
||||||
|
const emptyState = document.createElement("div");
|
||||||
|
emptyState.classList.add("day-empty");
|
||||||
|
const img = document.createElement("img");
|
||||||
|
img.src = browser.runtime.getURL(LogoLight);
|
||||||
|
const text = document.createElement("p");
|
||||||
|
text.innerText = "No notices available.";
|
||||||
|
emptyState.append(img, text);
|
||||||
|
noticeContainer.append(emptyState);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cleanup;
|
return cleanup;
|
||||||
@@ -226,11 +247,18 @@ async function GetActiveClasses() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupNotices(labelArray: string[], date: string) {
|
function setupNotices(labelArray: string[], date: string) {
|
||||||
|
console.info("[BetterSEQTA+] Notices: setupNotices called", {
|
||||||
|
labelArray,
|
||||||
|
date,
|
||||||
|
labelCount: labelArray.length,
|
||||||
|
});
|
||||||
|
|
||||||
const dateControl = document.querySelector(
|
const dateControl = document.querySelector(
|
||||||
'input[type="date"]',
|
'input[type="date"]',
|
||||||
) as HTMLInputElement;
|
) as HTMLInputElement;
|
||||||
|
|
||||||
const fetchNotices = async (date: string) => {
|
const fetchNotices = async (date: string) => {
|
||||||
|
console.info("[BetterSEQTA+] Notices: fetchNotices start", { date });
|
||||||
try {
|
try {
|
||||||
const data = settingsState.mockNotices
|
const data = settingsState.mockNotices
|
||||||
? getMockNotices()
|
? getMockNotices()
|
||||||
@@ -242,6 +270,12 @@ function setupNotices(labelArray: string[], date: string) {
|
|||||||
})
|
})
|
||||||
).json();
|
).json();
|
||||||
|
|
||||||
|
console.info("[BetterSEQTA+] Notices: fetchNotices response", {
|
||||||
|
date,
|
||||||
|
hasPayload: !!data?.payload,
|
||||||
|
payloadLength: Array.isArray(data?.payload) ? data.payload.length : "n/a",
|
||||||
|
rawKeys: data ? Object.keys(data) : [],
|
||||||
|
});
|
||||||
processNotices(data, labelArray);
|
processNotices(data, labelArray);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[BetterSEQTA+] Failed to fetch notices:", error);
|
console.error("[BetterSEQTA+] Failed to fetch notices:", error);
|
||||||
@@ -274,20 +308,45 @@ function comparedate(obj1: any, obj2: any) {
|
|||||||
}
|
}
|
||||||
function processNotices(response: any, labelArray: string[]) {
|
function processNotices(response: any, labelArray: string[]) {
|
||||||
const NoticeContainer = document.getElementById("notice-container");
|
const NoticeContainer = document.getElementById("notice-container");
|
||||||
if (!NoticeContainer) return;
|
if (!NoticeContainer) {
|
||||||
|
console.warn("[BetterSEQTA+] Notices: processNotices — notice-container not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
NoticeContainer.innerHTML = "";
|
NoticeContainer.innerHTML = "";
|
||||||
|
|
||||||
const notices = response.payload;
|
const notices = response?.payload;
|
||||||
|
if (!Array.isArray(notices)) {
|
||||||
|
console.warn("[BetterSEQTA+] Notices: processNotices — invalid or missing payload", {
|
||||||
|
hasResponse: !!response,
|
||||||
|
payloadType: typeof response?.payload,
|
||||||
|
});
|
||||||
|
const emptyState = document.createElement("div");
|
||||||
|
emptyState.classList.add("day-empty");
|
||||||
|
const img = document.createElement("img");
|
||||||
|
img.src = browser.runtime.getURL(LogoLight);
|
||||||
|
const text = document.createElement("p");
|
||||||
|
text.innerText = "No notices for today.";
|
||||||
|
emptyState.append(img, text);
|
||||||
|
NoticeContainer.append(emptyState);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!notices.length) {
|
if (!notices.length) {
|
||||||
const dummyNotice = document.createElement("div");
|
console.info("[BetterSEQTA+] Notices: processNotices — no notices for date");
|
||||||
dummyNotice.textContent = "No notices for today.";
|
const emptyState = document.createElement("div");
|
||||||
dummyNotice.classList.add("dummynotice");
|
emptyState.classList.add("day-empty");
|
||||||
NoticeContainer.append(dummyNotice);
|
const img = document.createElement("img");
|
||||||
|
img.src = browser.runtime.getURL(LogoLight);
|
||||||
|
const text = document.createElement("p");
|
||||||
|
text.innerText = "No notices for today.";
|
||||||
|
emptyState.append(img, text);
|
||||||
|
NoticeContainer.append(emptyState);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fragment = document.createDocumentFragment();
|
const fragment = document.createDocumentFragment();
|
||||||
|
let includedCount = 0;
|
||||||
|
|
||||||
notices.forEach((notice: any) => {
|
notices.forEach((notice: any) => {
|
||||||
const shouldInclude =
|
const shouldInclude =
|
||||||
@@ -295,12 +354,17 @@ function processNotices(response: any, labelArray: string[]) {
|
|||||||
labelArray.includes(JSON.stringify(notice.label));
|
labelArray.includes(JSON.stringify(notice.label));
|
||||||
|
|
||||||
if (shouldInclude) {
|
if (shouldInclude) {
|
||||||
|
includedCount++;
|
||||||
const colour = processNoticeColor(notice.colour);
|
const colour = processNoticeColor(notice.colour);
|
||||||
const noticeElement = createNoticeElement(notice, colour);
|
const noticeElement = createNoticeElement(notice, colour);
|
||||||
fragment.appendChild(noticeElement);
|
fragment.appendChild(noticeElement);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.info("[BetterSEQTA+] Notices: processNotices — rendered", {
|
||||||
|
totalFromApi: notices.length,
|
||||||
|
includedAfterFilter: includedCount,
|
||||||
|
});
|
||||||
NoticeContainer.appendChild(fragment);
|
NoticeContainer.appendChild(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user