l-min-components 1.6.1228 → 1.6.1231

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.1228",
3
+ "version": "1.6.1231",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -734,10 +734,74 @@ const useMessageKit = (/*affiliatesActive*/) => {
734
734
  // await readRoomMessages(newChatMessage.id); // Depends on desired logic
735
735
  };
736
736
 
737
+ const pinRoom = async (roomId) => {
738
+ // Optimistic update
739
+ setState((prevState) => {
740
+ return {
741
+ ...prevState,
742
+ roomsByCourses: prevState.roomsByCourses.map((courseGroup) => {
743
+ const roomIndex = courseGroup.rooms.findIndex(
744
+ (room) => room.id === roomId
745
+ );
746
+ if (roomIndex !== -1) {
747
+ const updatedRooms = [...courseGroup.rooms];
748
+ const oldPinStatus = updatedRooms[roomIndex].pin_status;
749
+ updatedRooms[roomIndex] = {
750
+ ...updatedRooms[roomIndex],
751
+ pin_status: !oldPinStatus,
752
+ };
753
+
754
+ const shouldCourseGroupBePinned = updatedRooms.some(
755
+ (room) => room.pin_status
756
+ );
757
+
758
+ return {
759
+ ...courseGroup,
760
+ pin_status: shouldCourseGroupBePinned,
761
+ rooms: updatedRooms,
762
+ };
763
+ }
764
+ return courseGroup;
765
+ }),
766
+ };
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: "POST",
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: "POST",
785
+ });
786
+ } // incomplete
787
+
788
+ if (!response?.data) {
789
+ // Revert optimistic update on failure (optional, depends on desired UX)
790
+ // You might want to implement more specific error handling here
791
+ getMessageRoomsByCourses(null, true);
792
+ return;
793
+ }
794
+ const isPinned = response.data.detail === "True";
795
+ // The optimistic update should ideally handle the UI change,
796
+ // so no further state update might be needed here based on the response.
797
+ // However, you could add a check to ensure the optimistic update matches the server response.
798
+ };
799
+
737
800
  // Initial data fetch effect
738
801
  useEffect(() => {
739
802
  (async () => {
740
803
  await getMessageRoomsByCourses();
804
+ // await pinRoom("5be9b48281ac4c2885d3b719654ed59d");
741
805
  // Example: Fetch initial chat for a specific room if needed on load
742
806
  // await getIndividualChats(null, "5be9b48281ac4c2885d3b719654ed59d");
743
807
  // await readRoomMessages({
@@ -951,6 +1015,7 @@ const useMessageKit = (/*affiliatesActive*/) => {
951
1015
  readRoomMessages,
952
1016
  addAutoReadRooms, // Expose new function
953
1017
  removeAutoReadRooms, // Expose new function
1018
+ pinRoom,
954
1019
  };
955
1020
  };
956
1021