feat: implement SSE real-time frontend updates on new payload reception
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 57s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 57s
This commit is contained in:
@@ -36,6 +36,27 @@ const Layout = () => {
|
||||
};
|
||||
|
||||
loadInitial();
|
||||
|
||||
// Set up SSE for real-time updates
|
||||
const API_URL = import.meta.env.VITE_API_URL || '/api';
|
||||
const sse = new EventSource(`${API_URL}/stream`);
|
||||
|
||||
sse.onmessage = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.type === 'update') {
|
||||
fetchData().then(newData => {
|
||||
setOrdersData(newData);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("SSE parse error", e);
|
||||
}
|
||||
};
|
||||
|
||||
return () => {
|
||||
sse.close();
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user