Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions frontend/src/app/(dashboard)/kds/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@
const [loginEmail, setLoginEmail] = useState('');
const [loginPassword, setLoginPassword] = useState('');
const [loginError, setLoginError] = useState('');
const [loginLoading, setLoginLoading] = useState(false);

Check warning on line 75 in frontend/src/app/(dashboard)/kds/page.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

'setLoginLoading' is assigned a value but never used
const wsRef = useRef<WebSocket | null>(null);
const restIntervalRef = useRef<NodeJS.Timeout | null>(null);

const stopRestPolling = useCallback(() => {
if (restIntervalRef.current) {
clearInterval(restIntervalRef.current);
restIntervalRef.current = null;
}
}, []);

const fetchOrdersRest = useCallback(async () => {
try {
const { data } = await api.get(`/kitchen/orders?status=pending,preparing,ready,served`);
Expand All @@ -88,18 +95,12 @@
}, []);

const startRestPolling = useCallback(() => {
stopRestPolling();
setConnectionMode('rest');
setConnected(true);
fetchOrdersRest();
restIntervalRef.current = setInterval(fetchOrdersRest, 5000);
}, [fetchOrdersRest]);

const stopRestPolling = useCallback(() => {
if (restIntervalRef.current) {
clearInterval(restIntervalRef.current);
restIntervalRef.current = null;
}
}, []);
}, [fetchOrdersRest, stopRestPolling]);

const updateItemStatus = useCallback(async (itemId: number, status: KitchenStatus) => {
setUpdating(itemId);
Expand Down Expand Up @@ -232,10 +233,10 @@
connectionTimeout = setTimeout(() => {
if (ws.readyState === WebSocket.CONNECTING) {
ws.close();
startRestPolling();
setConnectionMode('rest');
}
}, 5000);
}, [startRestPolling]);
}, []);

useEffect(() => {
const savedUser = localStorage.getItem('kds_user');
Expand Down Expand Up @@ -266,7 +267,7 @@
startRestPolling();
}
return () => stopRestPolling();
}, [connectionMode, user, startRestPolling]);
}, [connectionMode, user, startRestPolling, stopRestPolling]);

const filteredOrders = orders
.map((order) => ({
Expand Down
19 changes: 10 additions & 9 deletions frontend/src/app/kds-standalone/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ export default function KdsStandalonePage() {
const wsRef = useRef<WebSocket | null>(null);
const restIntervalRef = useRef<NodeJS.Timeout | null>(null);

const stopRestPolling = useCallback(() => {
if (restIntervalRef.current) {
clearInterval(restIntervalRef.current);
restIntervalRef.current = null;
}
}, []);

const fetchOrdersRest = useCallback(async () => {
try {
const { data } = await api.get('/api/kds/orders');
Expand All @@ -149,21 +156,15 @@ export default function KdsStandalonePage() {
}
setConnected(false);
}
}, []);
}, [stopRestPolling]);

const startRestPolling = useCallback(() => {
stopRestPolling();
setConnectionMode('rest');
setConnected(true);
fetchOrdersRest();
restIntervalRef.current = setInterval(fetchOrdersRest, 5000);
}, [fetchOrdersRest]);

const stopRestPolling = useCallback(() => {
if (restIntervalRef.current) {
clearInterval(restIntervalRef.current);
restIntervalRef.current = null;
}
}, []);
}, [fetchOrdersRest, stopRestPolling]);

const updateItemStatus = useCallback(async (itemId: number, status: KitchenStatus) => {
setUpdating(itemId);
Expand Down
Loading