@esvndev/es-react-template-chat 0.0.87 → 0.0.88

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/dist/index.mjs CHANGED
@@ -27368,6 +27368,16 @@ const encodeUUID = (uuid) => {
27368
27368
  return uuid;
27369
27369
  }
27370
27370
  };
27371
+ const isValidUrl = (string) => {
27372
+ try {
27373
+ // eslint-disable-next-line no-new
27374
+ new URL(string);
27375
+ return true;
27376
+ }
27377
+ catch (e) {
27378
+ return false;
27379
+ }
27380
+ };
27371
27381
  // ** Checks if the passed date is today
27372
27382
  const isToday = (value) => {
27373
27383
  const today = new Date();
@@ -72079,7 +72089,7 @@ const ChatLog = (props) => {
72079
72089
  useRef(null);
72080
72090
  const containerChatRef = useRef(null);
72081
72091
  const { connectHub, dataInfo, dataProfile, handleUser, handleUserSidebarRight, handleSidebar, handleSidebarRight, userSidebarLeft, dataHistory, chatGetType, approveUpdateStatus, handleModalAdministrative, setDataItem, handleModalAddUserGroup, handleModalGroup, typeOpenModalAdd, setTypeOpenModalAdd, unpinMessage, getPinnedMessages } = props;
72082
- dataHistory?.find((dt) => dt.id === active);
72092
+ const groupChatUsers = dataHistory?.find((dt) => dt.id === active);
72083
72093
  //const dataInfoAvatar = dataInfo && dataInfo.avatar ? dataInfo.avatar : DEFAULT_AVATAR
72084
72094
  useState([]);
72085
72095
  useState(false);
@@ -72105,31 +72115,35 @@ const ChatLog = (props) => {
72105
72115
  useState(false);
72106
72116
  useState(new Set());
72107
72117
  useState(true);
72108
- // // Load initial messages
72109
- // useEffect(() => {
72110
- // if (!checkScroll) {
72111
- // scrollToBottom()
72112
- // }
72113
- // }, [messageByGroup, checkScroll])
72114
- // const mentionItems = useMemo(() => {
72115
- // if (!groupChatUsers) { return [] }
72116
- // const users = Array.isArray(groupChatUsers.users) ? groupChatUsers.users : []
72117
- // const mappedUsers = users.map((user: any) => {
72118
- // const rawAvatar = user.avatar
72119
- // let avatar = DEFAULT_AVATAR
72120
- // if (rawAvatar) {
72121
- // avatar = isValidUrl(rawAvatar) ? rawAvatar : `${CDN_URL_VIEW}/${rawAvatar}`
72122
- // }
72123
- // return {
72124
- // ...user,
72125
- // avatar
72126
- // }
72127
- // })
72128
- // return [{ id: "all", name: "All" }, ...mappedUsers]
72129
- // }, [groupChatUsers])
72130
- // const toggleModalPreview = () => {
72131
- // setOpenModalPreview(!openModalPreview)
72132
- // }
72118
+ const scrollToBottom = () => {
72119
+ const messagesEndEle = document.getElementById('messagesEnd');
72120
+ messagesEndEle?.scrollIntoView({ block: 'end', behavior: "instant" });
72121
+ };
72122
+ //từ đây
72123
+ // Load initial messages
72124
+ useEffect(() => {
72125
+ if (!checkScroll) {
72126
+ scrollToBottom();
72127
+ }
72128
+ }, [messageByGroup, checkScroll]);
72129
+ useMemo(() => {
72130
+ if (!groupChatUsers) {
72131
+ return [];
72132
+ }
72133
+ const users = Array.isArray(groupChatUsers.users) ? groupChatUsers.users : [];
72134
+ const mappedUsers = users.map((user) => {
72135
+ const rawAvatar = user.avatar;
72136
+ let avatar = DEFAULT_AVATAR;
72137
+ if (rawAvatar) {
72138
+ avatar = isValidUrl(rawAvatar) ? rawAvatar : `${CDN_URL_VIEW}/${rawAvatar}`;
72139
+ }
72140
+ return {
72141
+ ...user,
72142
+ avatar
72143
+ };
72144
+ });
72145
+ return [{ id: "all", name: "All" }, ...mappedUsers];
72146
+ }, [groupChatUsers]);
72133
72147
  // const handlePreview = useCallback((mes: any) => {
72134
72148
  // setSelectedMessage(mes)
72135
72149
  // setOpenModalPreview(true)