This pull request enhances the classroom chat feature by refining error handling, improving state management, and restructuring the code for better readability and maintainability. Key updates include integrating error handling into the Redux state, refining chat-related API requests, and ensuring a smooth user experience when joining and managing classrooms.
Changes
Redux State Management:
Added errorMessage to initialState in chatSlice.js.
Integrated errorMessage state update into extra reducers in chatSlice.js.
Refactored token extraction in chat thunk functions using thunkAPI's auth state.
Updated validation logic in thunk functions to handle errors based on response.data.
Integrated thunks for getting and joining classrooms from the chat Redux state.
User Notifications:
Integrated toast notifications for user feedback on actions.
Implemented useEffect to dispatch getClassrooms action when the classroom list is empty.
Added useEffect for logging errors and displaying error messages to the console.
Classroom Management:
Implemented handleChange function for managing classroom state updates.
Added handleJoinClassroom function to dispatch actions and notify users of successful operations.
Integrated logic and HTML elements for rendering and joining classrooms based on the current state.
Socket and Server Configuration:
Changed handleSocketConnection argument from server to io in socketController.js.
Implemented global error and response handling in server.js.
API Adjustments:
Renamed joinClassroom argument from classroomName to classroomId and updated the corresponding request string and authorization configuration in chatService.js.
Reordered functions in chatService.js for clarity and improved code structure.
Fixed the getClassroomMessages request protocol from DELETE to GET and updated the API endpoint string in chatService.js.
Code Cleanup:
Removed comments and adjusted classroom ID querying in chatController.js.
Moved leaveClassroom function in chatController.js for better readability.
Uncommented the API endpoint for leaving classrooms in chatRoutes.js.
Relocated the leaveClassroom thunk in chatSlice.js for improved code structure.
Removed redundant Redux hooks (useSelector) and state maintenance in Dashboard.jsx.
Fixed the API endpoint string for chat routes in router.js.
Summary
This pull request enhances the classroom chat feature by refining error handling, improving state management, and restructuring the code for better readability and maintainability. Key updates include integrating error handling into the Redux state, refining chat-related API requests, and ensuring a smooth user experience when joining and managing classrooms.
Changes
Redux State Management:
errorMessage
toinitialState
inchatSlice.js
.errorMessage
state update into extra reducers inchatSlice.js
.thunkAPI
's auth state.response.data
.User Notifications:
toast
notifications for user feedback on actions.useEffect
to dispatchgetClassrooms
action when the classroom list is empty.useEffect
for logging errors and displaying error messages to the console.Classroom Management:
handleChange
function for managing classroom state updates.handleJoinClassroom
function to dispatch actions and notify users of successful operations.Socket and Server Configuration:
handleSocketConnection
argument fromserver
toio
insocketController.js
.server.js
.API Adjustments:
joinClassroom
argument fromclassroomName
toclassroomId
and updated the corresponding request string and authorization configuration inchatService.js
.chatService.js
for clarity and improved code structure.getClassroomMessages
request protocol from DELETE to GET and updated the API endpoint string inchatService.js
.Code Cleanup:
chatController.js
.leaveClassroom
function inchatController.js
for better readability.chatRoutes.js
.leaveClassroom
thunk inchatSlice.js
for improved code structure.useSelector
) and state maintenance inDashboard.jsx
.router.js
.