mirror of https://github.com/langgenius/dify.git
chore: use console.warn instead of toast
This commit is contained in:
parent
aa92f0dd32
commit
50c8b699a8
|
|
@ -1307,12 +1307,12 @@ export class CollaborationManager {
|
|||
this.emitGraphViewActive(this.graphViewActive)
|
||||
})
|
||||
|
||||
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/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,12 @@ 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
|
||||
|
||||
|
|
@ -115,10 +121,11 @@ export function useCollaboration(appId: string, reactFlowStore?: ReactFlowStore)
|
|||
const prevIsConnected = useRef(false)
|
||||
useEffect(() => {
|
||||
if (prevIsConnected.current && !state.isConnected) {
|
||||
Toast.notify({
|
||||
type: 'error',
|
||||
message: '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