This PR introduces several key improvements across the codebase, focusing on enhancing error handling for Redux slices and services, refining classroom management logic, and better organizing socket event management. The updates improve code readability, maintainability, and the clarity of functions' purposes, ensuring that components utilizing the chat context in Dashboard.jsx operate smoothly.
Changes
Error Handling Enhancements:
Renamed service.errorHandler.js to redux.errorHandler.js to reflect its broader application.
Added handleServiceError and handleSliceError functions for handling errors in service functions and Redux slices, respectively.
Integrated handleServiceError into service functions in classroomService.js and chatService.js.
Integrated handleSliceError into functions in classroomSlice.js.
Socket Event Management:
Implemented handleSocketEvents for managing socket event listeners, focusing on handling the newMessage and chatOpen events.
The function dispatches sendMessage when a new message is received and dispatches updateMessageStatus to mark messages as read when a chat is opened.
Added error handling for null socket instances.
Moved the initSocket function from chatContext to a new socketManager.js module to improve code organization.
Classroom Management:
Returned classroom ID on successful joinClassroom requests in classroomController.js.
Renamed getClassrooms to getAllClassrooms in classroomController.js for clarity.
Implemented getUserClassrooms in classroomController.js to fetch classrooms specific to the authenticated user.
Integrated getAllClassrooms and getUserClassrooms into their respective API endpoints in classroomRoutes.js.
Chat Context Refactor:
Moved ChatProvider integration from Chat.jsx to Dashboard.jsx, enabling components in Dashboard to utilize chat context.
Added selectedChat and setSelectedChat to the contextValue for better state management within the chat context.
Integrated useDispatch, initSocket, and handleSocketEvents into chatContext.js for managing socket connections.
Codebase Cleanup:
Removed unnecessary ChatProvider integration from Chat.jsx for cleaner code.
Improved code readability and separation of concerns across modules, particularly in socket management and classroom handling.
Summary
This PR introduces several key improvements across the codebase, focusing on enhancing error handling for Redux slices and services, refining classroom management logic, and better organizing socket event management. The updates improve code readability, maintainability, and the clarity of functions' purposes, ensuring that components utilizing the chat context in
Dashboard.jsx
operate smoothly.Changes
Error Handling Enhancements:
service.errorHandler.js
toredux.errorHandler.js
to reflect its broader application.handleServiceError
andhandleSliceError
functions for handling errors in service functions and Redux slices, respectively.handleServiceError
into service functions inclassroomService.js
andchatService.js
.handleSliceError
into functions inclassroomSlice.js
.Socket Event Management:
handleSocketEvents
for managing socket event listeners, focusing on handling thenewMessage
andchatOpen
events.sendMessage
when a new message is received and dispatchesupdateMessageStatus
to mark messages as read when a chat is opened.initSocket
function fromchatContext
to a newsocketManager.js
module to improve code organization.Classroom Management:
joinClassroom
requests inclassroomController.js
.getClassrooms
togetAllClassrooms
inclassroomController.js
for clarity.getUserClassrooms
inclassroomController.js
to fetch classrooms specific to the authenticated user.getAllClassrooms
andgetUserClassrooms
into their respective API endpoints inclassroomRoutes.js
.Chat Context Refactor:
ChatProvider
integration fromChat.jsx
toDashboard.jsx
, enabling components inDashboard
to utilize chat context.selectedChat
andsetSelectedChat
to thecontextValue
for better state management within the chat context.useDispatch
,initSocket
, andhandleSocketEvents
intochatContext.js
for managing socket connections.Codebase Cleanup:
ChatProvider
integration fromChat.jsx
for cleaner code.