Websocket and SSE in working state :
Add Server-Sent Events (SSE) support with connection status and settings components - Implemented SSEConnectionStatus component to display real-time connection status. - Created SSESettings component for enabling/disabling SSE based on user profile. - Introduced SSEContext and useSSE hook for managing SSE connections and state. - Added auto-connect functionality for SSE based on user profile and token validity. - Updated WebSocketSettings to ensure proper handling of WebSocket state. - Enhanced MyChores view with bulk archive functionality and improved UI feedback. - Refactored NotificationSetting to ensure boolean values are set correctly. - Updated Settings view to include RealTimeSettings component for SSE configuration.
This commit is contained in:
25
src/contexts/SSEContext.jsx
Normal file
25
src/contexts/SSEContext.jsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createContext, useContext } from 'react'
|
||||
import { useSSE } from '../hooks/useSSE'
|
||||
|
||||
export const SSEContext = createContext({
|
||||
connectionState: 2, // CLOSED
|
||||
isConnected: false,
|
||||
isConnecting: false,
|
||||
lastEvent: null,
|
||||
error: null,
|
||||
connect: () => {},
|
||||
disconnect: () => {},
|
||||
getConnectionStatus: () => 'disconnected',
|
||||
})
|
||||
|
||||
export const useSSEContext = () => {
|
||||
return useContext(SSEContext)
|
||||
}
|
||||
|
||||
export const SSEProvider = ({ children }) => {
|
||||
const sseState = useSSE()
|
||||
|
||||
return <SSEContext.Provider value={sseState}>{children}</SSEContext.Provider>
|
||||
}
|
||||
|
||||
export default SSEProvider
|
||||
Reference in New Issue
Block a user