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.
26 lines
597 B
JavaScript
26 lines
597 B
JavaScript
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
|