l-min-components 1.6.1232 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "l-min-components",
3
- "version": "1.6.1232",
3
+ "version": "1.6.1234",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -322,7 +322,7 @@ const useMessageKit = (/*affiliatesActive*/) => {
322
322
  }
323
323
 
324
324
  if (
325
- String(selectedAccount.type).toLowerCase() === "instructor" &&
325
+ selectedAccount.type.toLowerCase() === "instructor" &&
326
326
  affiliateAccount
327
327
  // &&
328
328
  // affiliatesActive
@@ -765,32 +765,31 @@ const useMessageKit = (/*affiliatesActive*/) => {
765
765
  }),
766
766
  };
767
767
  });
768
-
769
- let response;
770
- if (selectedAccount.type.toLowerCase() === "enterprise") {
771
- response = await request({
772
- url: `/notify/v1/enterprise/rooms/${roomId}/change_pin_status/`,
773
- method: "patch",
774
- });
775
- }
776
- if (
777
- selectedAccount.type.toLowerCase() === "instructor" &&
778
- affiliateAccount
779
- // &&
780
- // affiliatesActive
781
- ) {
782
- response = await request({
783
- url: `/notify/v1/instructor/${affiliateAccount}/rooms/${roomId}/change_pin_status/`,
784
- method: "patch",
785
- });
786
- } // incomplete
787
-
788
- if (!response?.data) {
768
+ try {
769
+ let response;
770
+ if (selectedAccount.type.toLowerCase() === "enterprise") {
771
+ response = await request({
772
+ url: `/notify/v1/enterprise/rooms/${roomId}/change_pin_status/`,
773
+ method: "patch",
774
+ });
775
+ }
776
+ if (
777
+ selectedAccount.type.toLowerCase() === "instructor" &&
778
+ affiliateAccount
779
+ // &&
780
+ // affiliatesActive
781
+ ) {
782
+ response = await request({
783
+ url: `/notify/v1/instructor/${affiliateAccount}/rooms/${roomId}/change_pin_status/`,
784
+ method: "patch",
785
+ });
786
+ } // incomplete
787
+ } catch (err) {
789
788
  // Revert optimistic update on failure (optional, depends on desired UX)
790
789
  // You might want to implement more specific error handling here
791
790
  getMessageRoomsByCourses(null, true);
792
- return;
793
791
  }
792
+
794
793
  // const isPinned = response.data.detail === "True";
795
794
  // The optimistic update should ideally handle the UI change,
796
795
  // so no further state update might be needed here based on the response.
@@ -798,18 +797,78 @@ const useMessageKit = (/*affiliatesActive*/) => {
798
797
  };
799
798
 
800
799
  const deleteRoom = async (roomId) => {
801
- let response;
802
- if (selectedAccount.type.toLowerCase() === "enterprise") {
803
- response = await request({
804
- url: ``,
805
- });
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);
806
864
  }
807
865
  };
808
866
  // Initial data fetch effect
809
867
  useEffect(() => {
810
868
  (async () => {
811
869
  await getMessageRoomsByCourses();
812
- await pinRoom("5be9b48281ac4c2885d3b719654ed59d");
870
+ // await deleteRoom("5be9b48281ac4c2885d3b719654ed59d");
871
+ // await pinRoom("5be9b48281ac4c2885d3b719654ed59d");
813
872
  // Example: Fetch initial chat for a specific room if needed on load
814
873
  // await getIndividualChats(null, "5be9b48281ac4c2885d3b719654ed59d");
815
874
  // await readRoomMessages({
@@ -1024,6 +1083,7 @@ const useMessageKit = (/*affiliatesActive*/) => {
1024
1083
  addAutoReadRooms, // Expose new function
1025
1084
  removeAutoReadRooms, // Expose new function
1026
1085
  pinRoom,
1086
+ deleteRoom,
1027
1087
  };
1028
1088
  };
1029
1089