@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.js CHANGED
@@ -27397,6 +27397,16 @@ const encodeUUID = (uuid) => {
27397
27397
  return uuid;
27398
27398
  }
27399
27399
  };
27400
+ const isValidUrl = (string) => {
27401
+ try {
27402
+ // eslint-disable-next-line no-new
27403
+ new URL(string);
27404
+ return true;
27405
+ }
27406
+ catch (e) {
27407
+ return false;
27408
+ }
27409
+ };
27400
27410
  // ** Checks if the passed date is today
27401
27411
  const isToday = (value) => {
27402
27412
  const today = new Date();
@@ -72108,7 +72118,7 @@ const ChatLog = (props) => {
72108
72118
  React.useRef(null);
72109
72119
  const containerChatRef = React.useRef(null);
72110
72120
  const { connectHub, dataInfo, dataProfile, handleUser, handleUserSidebarRight, handleSidebar, handleSidebarRight, userSidebarLeft, dataHistory, chatGetType, approveUpdateStatus, handleModalAdministrative, setDataItem, handleModalAddUserGroup, handleModalGroup, typeOpenModalAdd, setTypeOpenModalAdd, unpinMessage, getPinnedMessages } = props;
72111
- dataHistory?.find((dt) => dt.id === active);
72121
+ const groupChatUsers = dataHistory?.find((dt) => dt.id === active);
72112
72122
  //const dataInfoAvatar = dataInfo && dataInfo.avatar ? dataInfo.avatar : DEFAULT_AVATAR
72113
72123
  React.useState([]);
72114
72124
  React.useState(false);
@@ -72134,31 +72144,35 @@ const ChatLog = (props) => {
72134
72144
  React.useState(false);
72135
72145
  React.useState(new Set());
72136
72146
  React.useState(true);
72137
- // // Load initial messages
72138
- // useEffect(() => {
72139
- // if (!checkScroll) {
72140
- // scrollToBottom()
72141
- // }
72142
- // }, [messageByGroup, checkScroll])
72143
- // const mentionItems = useMemo(() => {
72144
- // if (!groupChatUsers) { return [] }
72145
- // const users = Array.isArray(groupChatUsers.users) ? groupChatUsers.users : []
72146
- // const mappedUsers = users.map((user: any) => {
72147
- // const rawAvatar = user.avatar
72148
- // let avatar = DEFAULT_AVATAR
72149
- // if (rawAvatar) {
72150
- // avatar = isValidUrl(rawAvatar) ? rawAvatar : `${CDN_URL_VIEW}/${rawAvatar}`
72151
- // }
72152
- // return {
72153
- // ...user,
72154
- // avatar
72155
- // }
72156
- // })
72157
- // return [{ id: "all", name: "All" }, ...mappedUsers]
72158
- // }, [groupChatUsers])
72159
- // const toggleModalPreview = () => {
72160
- // setOpenModalPreview(!openModalPreview)
72161
- // }
72147
+ const scrollToBottom = () => {
72148
+ const messagesEndEle = document.getElementById('messagesEnd');
72149
+ messagesEndEle?.scrollIntoView({ block: 'end', behavior: "instant" });
72150
+ };
72151
+ //từ đây
72152
+ // Load initial messages
72153
+ React.useEffect(() => {
72154
+ if (!checkScroll) {
72155
+ scrollToBottom();
72156
+ }
72157
+ }, [messageByGroup, checkScroll]);
72158
+ React.useMemo(() => {
72159
+ if (!groupChatUsers) {
72160
+ return [];
72161
+ }
72162
+ const users = Array.isArray(groupChatUsers.users) ? groupChatUsers.users : [];
72163
+ const mappedUsers = users.map((user) => {
72164
+ const rawAvatar = user.avatar;
72165
+ let avatar = DEFAULT_AVATAR;
72166
+ if (rawAvatar) {
72167
+ avatar = isValidUrl(rawAvatar) ? rawAvatar : `${CDN_URL_VIEW}/${rawAvatar}`;
72168
+ }
72169
+ return {
72170
+ ...user,
72171
+ avatar
72172
+ };
72173
+ });
72174
+ return [{ id: "all", name: "All" }, ...mappedUsers];
72175
+ }, [groupChatUsers]);
72162
72176
  // const handlePreview = useCallback((mes: any) => {
72163
72177
  // setSelectedMessage(mes)
72164
72178
  // setOpenModalPreview(true)