Clear stale WS locks on reconnect to fix phantom overlays
When WS reconnects after a disconnect, the browser may have missed unlock/booking:created messages, leaving gray striped overlays stuck forever. Clearing all locks on reconnect ensures stale state is removed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect, useCallback } from 'react'
|
import { useState, useEffect, useCallback, useRef } from 'react'
|
||||||
import { BookingCalendar } from '../components/calendar/BookingCalendar'
|
import { BookingCalendar } from '../components/calendar/BookingCalendar'
|
||||||
import { RENTAL_OBJECTS, MOCK_RENTAL_BOOKINGS } from '../data/rentalData'
|
import { RENTAL_OBJECTS, MOCK_RENTAL_BOOKINGS } from '../data/rentalData'
|
||||||
import { useModules } from '../contexts/ModulesContext'
|
import { useModules } from '../contexts/ModulesContext'
|
||||||
@@ -51,6 +51,15 @@ export function CalendarPage() {
|
|||||||
|
|
||||||
const { send, connected } = useHotelSocket({ slug, token: session?.token ?? null, onMessage: handleWsMessage })
|
const { send, connected } = useHotelSocket({ slug, token: session?.token ?? null, onMessage: handleWsMessage })
|
||||||
|
|
||||||
|
// Clear stale locks on WS reconnect (may have missed unlock/booking:created while disconnected)
|
||||||
|
const prevConnected = useRef(false)
|
||||||
|
useEffect(() => {
|
||||||
|
if (connected && !prevConnected.current) {
|
||||||
|
setLocks(new Map())
|
||||||
|
}
|
||||||
|
prevConnected.current = connected
|
||||||
|
}, [connected])
|
||||||
|
|
||||||
const handleCreate = async (data: Partial<Booking>) => {
|
const handleCreate = async (data: Partial<Booking>) => {
|
||||||
try {
|
try {
|
||||||
const created = await api.bookings.create(slug, {
|
const created = await api.bookings.create(slug, {
|
||||||
|
|||||||
Reference in New Issue
Block a user