backend updated for counter login

This commit is contained in:
Sidharth Prabhu
2026-04-17 08:25:17 +05:30
parent 5d247a09e9
commit 2d24b4d71b
4 changed files with 129 additions and 4 deletions

View File

@@ -114,6 +114,27 @@ const Products = () => {
useEffect(() => {
fetchProducts();
// SSE Real-time stock updates
const host = window.location.hostname;
const eventSource = new EventSource(`http://${host}:8080/api/stock/stream`);
eventSource.addEventListener('stockUpdate', (event: any) => {
try {
const update = JSON.parse(event.data);
setProducts(prevProducts =>
prevProducts.map(p =>
p.id === update.productId ? { ...p, stock: update.stock } : p
)
);
} catch (err) {
console.error('Error processing stock update:', err);
}
});
return () => {
eventSource.close();
};
}, [currentPage, pageSize, debouncedSearchTerm]);
useEffect(() => {