fix: Bugs created after the overhaul, performance and layout fixes
This commit is contained in:
@@ -1626,13 +1626,20 @@ export default function DeviceDetail() {
|
||||
const loadData = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const [d, mqttData] = await Promise.all([api.get(`/devices/${id}`), api.get("/mqtt/status").catch(() => null)]);
|
||||
// Phase 1: load device from DB immediately — renders page without waiting for MQTT
|
||||
const d = await api.get(`/devices/${id}`);
|
||||
setDevice(d);
|
||||
if (d.staffNotes) setStaffNotes(d.staffNotes);
|
||||
setLoading(false);
|
||||
|
||||
if (mqttData?.devices && d.device_id) {
|
||||
const match = mqttData.devices.find((s) => s.device_serial === d.device_id);
|
||||
setMqttStatus(match || null);
|
||||
// Phase 2: fire async background fetches — do not block the render
|
||||
if (d.device_id) {
|
||||
api.get("/mqtt/status").then((mqttData) => {
|
||||
if (mqttData?.devices) {
|
||||
const match = mqttData.devices.find((s) => s.device_serial === d.device_id);
|
||||
setMqttStatus(match || null);
|
||||
}
|
||||
}).catch(() => {});
|
||||
}
|
||||
|
||||
setUsersLoading(true);
|
||||
|
||||
Reference in New Issue
Block a user