l-min-components 1.6.1228 → 1.6.1232

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.1232",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -734,10 +734,82 @@ 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: "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) {
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
+
800
+ const deleteRoom = async (roomId) => {
801
+ let response;
802
+ if (selectedAccount.type.toLowerCase() === "enterprise") {
803
+ response = await request({
804
+ url: ``,
805
+ });
806
+ }
807
+ };
737
808
  // Initial data fetch effect
738
809
  useEffect(() => {
739
810
  (async () => {
740
811
  await getMessageRoomsByCourses();
812
+ await pinRoom("5be9b48281ac4c2885d3b719654ed59d");
741
813
  // Example: Fetch initial chat for a specific room if needed on load
742
814
  // await getIndividualChats(null, "5be9b48281ac4c2885d3b719654ed59d");
743
815
  // await readRoomMessages({
@@ -951,6 +1023,7 @@ const useMessageKit = (/*affiliatesActive*/) => {
951
1023
  readRoomMessages,
952
1024
  addAutoReadRooms, // Expose new function
953
1025
  removeAutoReadRooms, // Expose new function
1026
+ pinRoom,
954
1027
  };
955
1028
  };
956
1029