Update Settings.tsx

This commit is contained in:
2025-12-11 22:11:50 +01:00
committed by GitHub
parent 33b49304ba
commit 669f55a14d

View File

@@ -141,27 +141,42 @@ export const SettingsPage: React.FC = () => {
setActiveCondo(activeC); setActiveCondo(activeC);
setGlobalSettings(gSettings); setGlobalSettings(gSettings);
// Fetch condo-specific data ONLY if there is an active condo // Fetch condo-specific data individually to prevent one failure from blocking others
if (activeC) { if (activeC) {
const [fams, usrs, alrts, allNotices] = await Promise.all([ // Families
CondoService.getFamilies(activeC.id), try {
CondoService.getUsers(activeC.id), const fams = await CondoService.getFamilies(activeC.id);
CondoService.getAlerts(activeC.id), setFamilies(fams);
CondoService.getNotices(activeC.id) } catch(e) { console.error("Error fetching families", e); }
]);
setFamilies(fams); // Users
setUsers(usrs); try {
setAlerts(alrts); const usrs = await CondoService.getUsers(activeC.id);
setNotices(allNotices); setUsers(usrs);
} catch(e) { console.error("Error fetching users", e); }
// Alerts
try {
const alrts = await CondoService.getAlerts(activeC.id);
setAlerts(alrts);
} catch(e) { console.error("Error fetching alerts", e); }
// Notices
try {
const allNotices = await CondoService.getNotices(activeC.id);
setNotices(allNotices);
// Fetch read stats for notices
const stats: Record<string, NoticeRead[]> = {};
for (const n of allNotices) {
try {
const reads = await CondoService.getNoticeReadStatus(n.id);
stats[n.id] = reads;
} catch(e) { console.warn("Error reading notice status", e); }
}
setNoticeReadStats(stats);
} catch(e) { console.error("Error fetching notices", e); }
// Fetch read stats for notices
const stats: Record<string, NoticeRead[]> = {};
for (const n of allNotices) {
const reads = await CondoService.getNoticeReadStatus(n.id);
stats[n.id] = reads;
}
setNoticeReadStats(stats);
} else { } else {
setFamilies([]); setFamilies([]);
setUsers([]); setUsers([]);
@@ -174,7 +189,7 @@ export const SettingsPage: React.FC = () => {
setActiveCondo(activeC); setActiveCondo(activeC);
} }
} catch(e) { } catch(e) {
console.error(e); console.error("Global fetch error", e);
} finally { } finally {
setLoading(false); setLoading(false);
} }