mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-20 00:10:03 +02:00
fetch data as soon as the client connects to the websocket server
This commit is contained in:
parent
7f402b45e7
commit
69c5e0397b
@ -126,11 +126,6 @@ const App = () => {
|
|||||||
}, [state]);
|
}, [state]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Fetch data from the API when the component mounts
|
|
||||||
fetch(`http://${hostname}:${port}/service-properties`)
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data: DataServiceJSON) => dispatch({ type: 'SET_DATA', data }));
|
|
||||||
|
|
||||||
// Allow the user to add a custom css file
|
// Allow the user to add a custom css file
|
||||||
fetch(`http://${hostname}:${port}/custom.css`)
|
fetch(`http://${hostname}:${port}/custom.css`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
@ -145,7 +140,13 @@ const App = () => {
|
|||||||
})
|
})
|
||||||
.catch(console.error); // Handle the error appropriately
|
.catch(console.error); // Handle the error appropriately
|
||||||
|
|
||||||
socket.on('connect', () => setConnectionStatus('connected'));
|
socket.on('connect', () => {
|
||||||
|
// Fetch data from the API when the client connects
|
||||||
|
fetch(`http://${hostname}:${port}/service-properties`)
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data: DataServiceJSON) => dispatch({ type: 'SET_DATA', data }));
|
||||||
|
setConnectionStatus('connected');
|
||||||
|
});
|
||||||
socket.on('disconnect', () => {
|
socket.on('disconnect', () => {
|
||||||
setConnectionStatus('disconnected');
|
setConnectionStatus('disconnected');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -222,7 +223,7 @@ const App = () => {
|
|||||||
|
|
||||||
// While the data is loading
|
// While the data is loading
|
||||||
if (!state) {
|
if (!state) {
|
||||||
return <p>Loading...</p>;
|
return <ConnectionToast connectionStatus={connectionStatus} />;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user