Implement socket state management with Zustand and enhance connection handling

- Introduced a new Zustand store for managing socket connection status and socket ID, improving state management for real-time communication.
- Updated the ConnectionIndicator component to utilize the socket store for dynamic status updates, allowing for better integration with the socket connection state.
- Enhanced the SocketService class to update the socket connection status during various connection events, ensuring accurate status reporting.
- Refactored the TelegramLoginButton component to clarify JWT token handling in comments, improving code readability.

These changes enhance the application's real-time capabilities and provide a more robust user experience by accurately reflecting connection states.
This commit is contained in:
Steven Enamakel
2026-01-28 04:17:50 +05:30
parent 8c46040e20
commit 792da72bbf
4 changed files with 65 additions and 7 deletions
+28
View File
@@ -0,0 +1,28 @@
import { create } from 'zustand';
export type SocketConnectionStatus = 'connected' | 'disconnected' | 'connecting';
interface SocketState {
status: SocketConnectionStatus;
socketId: string | null;
setStatus: (status: SocketConnectionStatus) => void;
setSocketId: (socketId: string | null) => void;
reset: () => void;
}
export const useSocketStore = create<SocketState>((set) => ({
status: 'disconnected',
socketId: null,
setStatus: (status: SocketConnectionStatus) => {
set({ status });
},
setSocketId: (socketId: string | null) => {
set({ socketId });
},
reset: () => {
set({ status: 'disconnected', socketId: null });
},
}));