This pull request focuses on enhancing code readability, modularity, and the separation of concerns by restructuring the classroom-related logic. It moves relevant state and service functions from the chat module to a dedicated classroom module, improves error handling, and updates UI components to reflect these changes.
Changes
State Management:
Moved the classrooms field from the chat reducer's initial state to classroomSlice.js.
Relocated joinClassroom, leaveClassroom, and getClassrooms thunks, along with their associated state handling, from chatSlice.js to classroomSlice.js.
Integrated classroomReducer into the store configuration in store.js.
Service Refactoring:
Moved joinClassroom, leaveClassroom, and getClassrooms functions from chatService.js to classroomService.js.
Relocated the handleError function from chatService.js to a new module, service.errorHandler.js, and integrated it into classroomService.js.
Classroom Component Enhancements:
Implemented handleLeaveClassroom in Classroom.jsx to dispatch Redux actions, handle errors, and notify users of successful operations.
Changed the label HTML element for selecting a classroom to a paragraph in Classroom.jsx.
Updated the key for rendered dropdown elements to be based on the classroom ID in Classroom.jsx.
Added a button with handleLeaveClassroom as the onClick event listener in Classroom.jsx.
Chat Component Updates:
Integrated useSelector with necessary fields from chat and auth state in Chat.jsx.
Renamed selectedFriend and setSelectedFriend to selectedChat and setSelectedChat in Chat.jsx.
Implemented useEffect to handle state changes based on isError and errorMessage in Chat.jsx.
Changed rendering of mock chat data to reflect the newly implemented Redux state, with conditional rendering based on classroom size and selectedChat state.
Controller and Route Modifications:
Moved joinClassroom, leaveClassroom, and getClassrooms from chatController.js to classroomController.js.
Integrated classroom controller functions into matching route endpoints in classroomRoutes.js.
Integrated classroomRoutes into the matching classroom API endpoint in router.js.
Removed the integration of sendFriendMessage from the / API endpoint in chatRoutes.js.
Removed the conflicting route endpoint /classroom/:id in chatRoutes.js.
Implemented new route endpoints for sending and fetching classroom messages in chatRoutes.js.
Function and API Adjustments:
Refactored handleJoinClassroom and handleLeaveClassroom in Classroom.jsx to store the result and handle errors based on the dispatched actions.
Changed API URL and request strings to match the new classroom route in classroomService.js.
Sent an empty object as a request body in joinClassroom and leaveClassroom in classroomService.js.
Implemented validation and error handling based on the classroomId field in the joinClassroom thunk in classroomSlice.js.
Added isError field state handling for fulfilled leaveClassroom cases to manage state updates in classroomSlice.js.
Summary
This pull request focuses on enhancing code readability, modularity, and the separation of concerns by restructuring the classroom-related logic. It moves relevant state and service functions from the chat module to a dedicated classroom module, improves error handling, and updates UI components to reflect these changes.
Changes
State Management:
classrooms
field from the chat reducer's initial state toclassroomSlice.js
.joinClassroom
,leaveClassroom
, andgetClassrooms
thunks, along with their associated state handling, fromchatSlice.js
toclassroomSlice.js
.classroomReducer
into the store configuration instore.js
.Service Refactoring:
joinClassroom
,leaveClassroom
, andgetClassrooms
functions fromchatService.js
toclassroomService.js
.handleError
function fromchatService.js
to a new module,service.errorHandler.js
, and integrated it intoclassroomService.js
.Classroom Component Enhancements:
handleLeaveClassroom
inClassroom.jsx
to dispatch Redux actions, handle errors, and notify users of successful operations.Classroom.jsx
.key
for rendered dropdown elements to be based on the classroom ID inClassroom.jsx
.handleLeaveClassroom
as theonClick
event listener inClassroom.jsx
.Chat Component Updates:
useSelector
with necessary fields fromchat
andauth
state inChat.jsx
.selectedFriend
andsetSelectedFriend
toselectedChat
andsetSelectedChat
inChat.jsx
.useEffect
to handle state changes based onisError
anderrorMessage
inChat.jsx
.selectedChat
state.Controller and Route Modifications:
joinClassroom
,leaveClassroom
, andgetClassrooms
fromchatController.js
toclassroomController.js
.classroomRoutes.js
.classroomRoutes
into the matching classroom API endpoint inrouter.js
.sendFriendMessage
from the/
API endpoint inchatRoutes.js
./classroom/:id
inchatRoutes.js
.chatRoutes.js
.Function and API Adjustments:
handleJoinClassroom
andhandleLeaveClassroom
inClassroom.jsx
to store the result and handle errors based on the dispatched actions.classroomService.js
.joinClassroom
andleaveClassroom
inclassroomService.js
.classroomId
field in thejoinClassroom
thunk inclassroomSlice.js
.isError
field state handling for fulfilledleaveClassroom
cases to manage state updates inclassroomSlice.js
.Feel free to copy the above description.