Update Settings.tsx
This commit is contained in:
@@ -141,27 +141,42 @@ export const SettingsPage: React.FC = () => {
|
||||
setActiveCondo(activeC);
|
||||
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) {
|
||||
const [fams, usrs, alrts, allNotices] = await Promise.all([
|
||||
CondoService.getFamilies(activeC.id),
|
||||
CondoService.getUsers(activeC.id),
|
||||
CondoService.getAlerts(activeC.id),
|
||||
CondoService.getNotices(activeC.id)
|
||||
]);
|
||||
// Families
|
||||
try {
|
||||
const fams = await CondoService.getFamilies(activeC.id);
|
||||
setFamilies(fams);
|
||||
} catch(e) { console.error("Error fetching families", e); }
|
||||
|
||||
setFamilies(fams);
|
||||
setUsers(usrs);
|
||||
setAlerts(alrts);
|
||||
setNotices(allNotices);
|
||||
// Users
|
||||
try {
|
||||
const usrs = await CondoService.getUsers(activeC.id);
|
||||
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 {
|
||||
setFamilies([]);
|
||||
setUsers([]);
|
||||
@@ -174,7 +189,7 @@ export const SettingsPage: React.FC = () => {
|
||||
setActiveCondo(activeC);
|
||||
}
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
console.error("Global fetch error", e);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user