mirror of
https://github.com/langgenius/dify.git
synced 2026-04-15 18:06:36 +08:00
chore: use console.warn instead of toast
This commit is contained in:
parent
a68482da77
commit
4e660a128a
@ -1381,12 +1381,12 @@ export class CollaborationManager {
|
||||
this.pendingInitialSync = true
|
||||
})
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
socket.on('disconnect', (reason) => {
|
||||
this.cursors = {}
|
||||
this.isLeader = false
|
||||
this.leaderId = null
|
||||
this.pendingInitialSync = false
|
||||
this.eventEmitter.emit('stateChange', { isConnected: false })
|
||||
this.eventEmitter.emit('stateChange', { isConnected: false, disconnectReason: reason })
|
||||
this.eventEmitter.emit('cursors', {})
|
||||
})
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@ import type {
|
||||
OnlineUser,
|
||||
} from '../types/collaboration'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { toast } from '@/app/components/base/ui/toast'
|
||||
import { useGlobalPublicStore } from '@/context/global-public-context'
|
||||
import { collaborationManager } from '../core/collaboration-manager'
|
||||
import { CursorService } from '../services/cursor-service'
|
||||
@ -33,6 +32,7 @@ export function useCollaboration(appId: string, reactFlowStore?: ReactFlowStore)
|
||||
const [state, setState] = useState<CollaborationViewState>(initialState)
|
||||
|
||||
const cursorServiceRef = useRef<CursorService | null>(null)
|
||||
const lastDisconnectReasonRef = useRef<string | null>(null)
|
||||
const isCollaborationEnabled = useGlobalPublicStore(s => s.systemFeatures.enable_collaboration_mode)
|
||||
|
||||
useEffect(() => {
|
||||
@ -67,6 +67,11 @@ export function useCollaboration(appId: string, reactFlowStore?: ReactFlowStore)
|
||||
initCollaboration()
|
||||
|
||||
const unsubscribeStateChange = collaborationManager.onStateChange((newState: Partial<CollaborationState>) => {
|
||||
if (newState.isConnected === false)
|
||||
lastDisconnectReasonRef.current = newState.disconnectReason || newState.error || null
|
||||
if (newState.isConnected === true)
|
||||
lastDisconnectReasonRef.current = null
|
||||
|
||||
if (newState.isConnected === undefined)
|
||||
return
|
||||
|
||||
@ -105,7 +110,11 @@ export function useCollaboration(appId: string, reactFlowStore?: ReactFlowStore)
|
||||
const prevIsConnected = useRef(false)
|
||||
useEffect(() => {
|
||||
if (prevIsConnected.current && !state.isConnected) {
|
||||
toast.error('Network connection lost. Please check your network.')
|
||||
const reason = lastDisconnectReasonRef.current
|
||||
if (reason)
|
||||
console.warn('WebSocket disconnected:', reason)
|
||||
else
|
||||
console.warn('WebSocket disconnected.')
|
||||
}
|
||||
prevIsConnected.current = state.isConnected || false
|
||||
}, [state.isConnected])
|
||||
|
||||
@ -44,6 +44,8 @@ export type CollaborationState = {
|
||||
onlineUsers: OnlineUser[]
|
||||
cursors: Record<string, CursorPosition>
|
||||
nodePanelPresence: NodePanelPresenceMap
|
||||
disconnectReason?: string
|
||||
error?: string
|
||||
}
|
||||
|
||||
export type GraphSyncData = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user