refactor: updateSystemList function

This commit is contained in:
Henry Dollman
2025-02-05 20:21:57 -05:00
parent 5b478c11eb
commit f4480c7aa7

View File

@@ -42,33 +42,28 @@ const verifyAuth = () => {
}) })
} }
let isFetchingSystems = false; export const updateSystemList = (() => {
let isFetchingSystems = false
export const updateSystemList = async () => { return async () => {
if (isFetchingSystems) {
if (isFetchingSystems) return; return
}
isFetchingSystems = true isFetchingSystems = true
try { try {
const records = await pb const records = await pb
.collection<SystemRecord>("systems") .collection<SystemRecord>("systems")
.getFullList({ sort: "+name", fields: "id,name,host,info,status" }); .getFullList({ sort: "+name", fields: "id,name,host,info,status" })
if (records.length) { if (records.length) {
$systems.set(records); $systems.set(records)
} else { } else {
verifyAuth(); verifyAuth()
}
} catch (e: any) {
// Suppressing pocketbase auto-cancellation error
if (e.isAbort || e.status === 0) {
return;
} }
} finally { } finally {
isFetchingSystems = false isFetchingSystems = false
} }
}; }
})()
export const updateAlerts = () => { export const updateAlerts = () => {