l-min-components 1.6.1233 → 1.6.1234
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -322,7 +322,7 @@ const useMessageKit = (/*affiliatesActive*/) => {
|
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
if (
|
|
325
|
-
|
|
325
|
+
selectedAccount.type.toLowerCase() === "instructor" &&
|
|
326
326
|
affiliateAccount
|
|
327
327
|
// &&
|
|
328
328
|
// affiliatesActive
|
|
@@ -797,17 +797,77 @@ const useMessageKit = (/*affiliatesActive*/) => {
|
|
|
797
797
|
};
|
|
798
798
|
|
|
799
799
|
const deleteRoom = async (roomId) => {
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
800
|
+
// Optimistic update: Remove the room and potentially the group
|
|
801
|
+
let previousState;
|
|
802
|
+
setState((prevState) => {
|
|
803
|
+
previousState = { ...prevState };
|
|
804
|
+
let updatedRoomsByCourses = prevState.roomsByCourses
|
|
805
|
+
.map((courseGroup) => {
|
|
806
|
+
const updatedRooms = courseGroup.rooms.filter(
|
|
807
|
+
(room) => room.id !== roomId
|
|
808
|
+
);
|
|
809
|
+
|
|
810
|
+
if (
|
|
811
|
+
updatedRooms.length === 0 &&
|
|
812
|
+
courseGroup.rooms.some((room) => room.id === roomId)
|
|
813
|
+
) {
|
|
814
|
+
// If the deleted room was the last one, remove the entire group
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
return {
|
|
819
|
+
...courseGroup,
|
|
820
|
+
rooms: updatedRooms,
|
|
821
|
+
// Recalculate total unread count
|
|
822
|
+
total_unread_count: updatedRooms.reduce(
|
|
823
|
+
(sum, room) => sum + room.unread_count,
|
|
824
|
+
0
|
|
825
|
+
),
|
|
826
|
+
pin_status: updatedRooms.some((room) => room.pin_status),
|
|
827
|
+
};
|
|
828
|
+
})
|
|
829
|
+
.filter(Boolean); // Remove null entries (deleted groups)
|
|
830
|
+
|
|
831
|
+
const updatedChats = { ...prevState.chats };
|
|
832
|
+
delete updatedChats[roomId]; // Remove chat history
|
|
833
|
+
|
|
834
|
+
return {
|
|
835
|
+
...prevState,
|
|
836
|
+
roomsByCourses: updatedRoomsByCourses,
|
|
837
|
+
chats: updatedChats,
|
|
838
|
+
};
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
try {
|
|
842
|
+
let response;
|
|
843
|
+
if (selectedAccount.type.toLowerCase() === "enterprise") {
|
|
844
|
+
response = await request({
|
|
845
|
+
url: `/notify/v1/enterprise/rooms/${roomId}/`,
|
|
846
|
+
method: "delete",
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
if (
|
|
850
|
+
selectedAccount.type.toLowerCase() === "instructor" &&
|
|
851
|
+
affiliateAccount
|
|
852
|
+
// &&
|
|
853
|
+
// affiliatesActive
|
|
854
|
+
) {
|
|
855
|
+
response = await request({
|
|
856
|
+
url: `/notify/v1/instructor/${affiliateAccount}/rooms/${roomId}/`,
|
|
857
|
+
method: "delete",
|
|
858
|
+
});
|
|
859
|
+
} // incomplete
|
|
860
|
+
} catch (err) {
|
|
861
|
+
console.error("Error deleting room:", err);
|
|
862
|
+
// Revert the optimistic update on error
|
|
863
|
+
setState(previousState);
|
|
805
864
|
}
|
|
806
865
|
};
|
|
807
866
|
// Initial data fetch effect
|
|
808
867
|
useEffect(() => {
|
|
809
868
|
(async () => {
|
|
810
869
|
await getMessageRoomsByCourses();
|
|
870
|
+
// await deleteRoom("5be9b48281ac4c2885d3b719654ed59d");
|
|
811
871
|
// await pinRoom("5be9b48281ac4c2885d3b719654ed59d");
|
|
812
872
|
// Example: Fetch initial chat for a specific room if needed on load
|
|
813
873
|
// await getIndividualChats(null, "5be9b48281ac4c2885d3b719654ed59d");
|
|
@@ -1023,6 +1083,7 @@ const useMessageKit = (/*affiliatesActive*/) => {
|
|
|
1023
1083
|
addAutoReadRooms, // Expose new function
|
|
1024
1084
|
removeAutoReadRooms, // Expose new function
|
|
1025
1085
|
pinRoom,
|
|
1086
|
+
deleteRoom,
|
|
1026
1087
|
};
|
|
1027
1088
|
};
|
|
1028
1089
|
|