Build application shell with live runtime status

This commit is contained in:
litoral05
2026-05-20 12:22:40 +01:00
parent b38c374a81
commit 9fcf67c7ae
16 changed files with 672 additions and 6 deletions
@@ -0,0 +1,6 @@
export function useCurrentUser() {
return {
name: "Administrador",
initials: "AD",
};
}
@@ -0,0 +1,5 @@
export function useNotifications() {
return {
unreadCount: 0,
};
}
@@ -0,0 +1,33 @@
import { useEffect, useState } from "react";
import { fetchRuntimeConfig } from "../../../lib/api/systemApi";
import type { RuntimeConfig } from "../../../types/system";
export function useRuntimeConfig() {
const [runtimeConfig, setRuntimeConfig] = useState<RuntimeConfig | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
fetchRuntimeConfig()
.then((data) => {
setRuntimeConfig(data);
setError(null);
})
.catch((exception: unknown) => {
setError(
exception instanceof Error
? exception.message
: "Failed to fetch runtime config.",
);
})
.finally(() => {
setLoading(false);
});
}, []);
return {
runtimeConfig,
loading,
error,
};
}
@@ -0,0 +1,46 @@
import { useEffect, useState } from "react";
import { Client } from "@stomp/stompjs";
import type { TelemetryBroadcastMessage } from "../../../types/telemetry";
export function useTelemetryStream() {
const [message, setMessage] = useState<TelemetryBroadcastMessage | null>(null);
const [connected, setConnected] = useState(false);
useEffect(() => {
const client = new Client({
brokerURL: "ws://localhost:18450/ws",
reconnectDelay: 3000,
onConnect: () => {
setConnected(true);
client.subscribe("/topic/telemetry/latest", (frame) => {
const payload = JSON.parse(frame.body) as TelemetryBroadcastMessage;
setMessage(payload);
});
},
onWebSocketClose: () => {
setConnected(false);
},
onStompError: () => {
setConnected(false);
},
});
client.activate();
return () => {
client.deactivate();
};
}, []);
return {
connected,
message,
lastTimestamp: message?.timestamp ?? null,
snapshots: message?.snapshots ?? [],
sensorCount: message?.sensorCount ?? 0,
};
}