add toast when disconnected

This commit is contained in:
hjlarry 2026-01-13 22:08:59 +08:00
parent 7f6c93bdce
commit d1c64f5c74
1 changed files with 12 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import { collaborationManager } from '../core/collaboration-manager'
import { CursorService } from '../services/cursor-service'
import type { CollaborationState } from '../types/collaboration'
import { useGlobalPublicStore } from '@/context/global-public-context'
import Toast from '@/app/components/base/toast'
export function useCollaboration(appId: string, reactFlowStore?: any) {
const [state, setState] = useState<Partial<CollaborationState & { isLeader: boolean }>>({
@ -88,6 +89,17 @@ export function useCollaboration(appId: string, reactFlowStore?: any) {
}
}, [appId, reactFlowStore, isCollaborationEnabled])
const prevIsConnected = useRef(false)
useEffect(() => {
if (prevIsConnected.current && !state.isConnected) {
Toast.notify({
type: 'error',
message: 'Network connection lost. Please check your network.',
})
}
prevIsConnected.current = state.isConnected || false
}, [state.isConnected])
const startCursorTracking = (containerRef: React.RefObject<HTMLElement>, reactFlowInstance?: ReactFlowInstance) => {
if (!isCollaborationEnabled || !cursorServiceRef.current)
return