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

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
@@ -17,9 +17,9 @@ import { isNullOrUndefined as isNullOrUndefined$2 } from '@src/utility/hooks/isN
17
17
  import avatarDefault from '@core/assets/images/avatars/avatar-blank.png';
18
18
  import '@draft-js-plugins/mention/lib/plugin.css';
19
19
  import '@draft-js-plugins/emoji/lib/plugin.css';
20
+ import { useDispatch } from 'react-redux';
20
21
  import { useAppDispatch as useAppDispatch$1, useAppSelector as useAppSelector$1 } from '@store/configureStore';
21
22
  import { useLocation } from 'react-router-dom';
22
- import { useDispatch } from 'react-redux';
23
23
 
24
24
  var instances = 'ej2_instances';
25
25
  var uid = 0;
@@ -72093,7 +72093,7 @@ const ChatLog = (props) => {
72093
72093
  //const dataInfoAvatar = dataInfo && dataInfo.avatar ? dataInfo.avatar : DEFAULT_AVATAR
72094
72094
  useState([]);
72095
72095
  useState(false);
72096
- useState(false);
72096
+ const [openModalPreview, setOpenModalPreview] = useState(false);
72097
72097
  useState(false);
72098
72098
  useState(false);
72099
72099
  useState(false);
@@ -72104,7 +72104,7 @@ const ChatLog = (props) => {
72104
72104
  useState({ x: 0, y: 0 });
72105
72105
  useState(undefined);
72106
72106
  useState(undefined);
72107
- useState(null);
72107
+ const [selectedMessage, setSelectedMessage] = useState(null);
72108
72108
  useState(false);
72109
72109
  useState(true);
72110
72110
  useRef(0);
@@ -72119,7 +72119,6 @@ const ChatLog = (props) => {
72119
72119
  const messagesEndEle = document.getElementById('messagesEnd');
72120
72120
  messagesEndEle?.scrollIntoView({ block: 'end', behavior: "instant" });
72121
72121
  };
72122
- //từ đây
72123
72122
  // Load initial messages
72124
72123
  useEffect(() => {
72125
72124
  if (!checkScroll) {
@@ -72144,159 +72143,13 @@ const ChatLog = (props) => {
72144
72143
  });
72145
72144
  return [{ id: "all", name: "All" }, ...mappedUsers];
72146
72145
  }, [groupChatUsers]);
72147
- // const handlePreview = useCallback((mes: any) => {
72148
- // setSelectedMessage(mes)
72149
- // setOpenModalPreview(true)
72150
- // }, [])
72151
- // const [isFetching, setIsFetching] = useState(false)
72152
- // const dispatch = useDispatch()
72153
- // const handleStartConversation = () => {
72154
- // if (
72155
- // !Object.keys({}).length &&
72156
- // !userSidebarLeft &&
72157
- // window.innerWidth < 992
72158
- // ) {
72159
- // handleSidebar()
72160
- // }
72161
- // }
72162
- // const uploadGroup = async (files: File[], type: 'image' | 'file') => {
72163
- // if (files.length === 0) { return }
72164
- // const batchId = newGuid()
72165
- // const errors: Array<{ file: File; error: any }> = []
72166
- // // Upload và gửi từng file một
72167
- // for (const file of files) {
72168
- // try {
72169
- // const result = await uploadWithRetry(file)
72170
- // if (result.success && chatRoomId) {
72171
- // const infoFiles = result.data?.infoFiles || []
72172
- // const items = type === 'image' ? infoFiles.map((x: any) => ({ ...x, batchId, createdDate: new Date().toISOString() })) : infoFiles
72173
- // // Gửi message ngay sau khi upload thành công
72174
- // connectHub(chatRoomId, {
72175
- // sendTo: dataInfo.id,
72176
- // content: '',
72177
- // type,
72178
- // path: JSON.stringify(items),
72179
- // typeChat
72180
- // })
72181
- // } else {
72182
- // errors.push({ file, error: result.error })
72183
- // }
72184
- // } catch (error) {
72185
- // errors.push({ file, error })
72186
- // }
72187
- // }
72188
- // // Thông báo lỗi nếu có
72189
- // if (errors.length > 0) {
72190
- // notificationError(`${errors.length}/${files.length} ${type === 'image' ? 'ảnh' : 'file'} upload thất bại`)
72191
- // }
72192
- // }
72193
- // const dataURLToFile = (dataUrl: string, fileName: string) => {
72194
- // const [header, data] = dataUrl.split(',')
72195
- // const mime = header.match(/data:(.*?);/)?.[1] || 'image/png'
72196
- // const binary = atob(data)
72197
- // const len = binary.length
72198
- // const u8 = new Uint8Array(len)
72199
- // for (let i = 0; i < len; i++) { u8[i] = binary.charCodeAt(i) }
72200
- // return new File([u8], fileName, { type: mime })
72201
- // }
72202
- // // ** Extract tagUserIds from editor mentions
72203
- // const extractTagUserIds = (): string[] => {
72204
- // const tagUserIds: string[] = []
72205
- // let hasAllMention = false
72206
- // editor.getEditorState().read(() => {
72207
- // const root = $getRoot()
72208
- // const nodes = root.getAllTextNodes()
72209
- // nodes.forEach((node) => {
72210
- // if ($isMentionNode(node)) {
72211
- // const userId = (node as any).__userId
72212
- // if (userId === 'all') {
72213
- // hasAllMention = true
72214
- // } else if (userId && !tagUserIds.includes(userId)) {
72215
- // tagUserIds.push(userId)
72216
- // }
72217
- // }
72218
- // })
72219
- // })
72220
- // // Nếu có @All, lấy tất cả userId trong nhóm
72221
- // if (hasAllMention && groupChatUsers?.users) {
72222
- // const allUserIds = groupChatUsers.users
72223
- // .map((user: any) => user.id)
72224
- // .filter((id: string) => id !== dataProfile?.id) // Loại bỏ chính mình
72225
- // return allUserIds
72226
- // }
72227
- // return tagUserIds
72228
- // }
72229
- // // ** Sends New Msg
72230
- // const handleSendMsg = (message: any) => {
72231
- // if (imgCopy.length > 0) {
72232
- // const imageFiles: File[] = []
72233
- // const otherFiles: File[] = []
72234
- // imgCopy.forEach((item: any, idx: number) => {
72235
- // const data = item?.data || item
72236
- // if (typeof data === 'string' && data.startsWith('data:image')) {
72237
- // imageFiles.push(dataURLToFile(data, item.name || `pasted_${Date.now()}_${idx}.png`))
72238
- // } else if (data instanceof File) {
72239
- // if (data.type?.startsWith('image')) {
72240
- // imageFiles.push(data)
72241
- // } else {
72242
- // otherFiles.push(data)
72243
- // }
72244
- // }
72245
- // })
72246
- // // Gửi ảnh trước rồi file
72247
- // uploadGroup(imageFiles, 'image')
72248
- // uploadGroup(otherFiles, 'file')
72249
- // }
72250
- // if (message.trim().length) {
72251
- // if (typingTimeoutRef.current) {
72252
- // clearTimeout(typingTimeoutRef.current)
72253
- // }
72254
- // isTypingRef.current = false
72255
- // if (connection && chatRoomId) {
72256
- // connection.invoke('StopTyping', chatRoomId).catch(console.error)
72257
- // }
72258
- // const tagUserIds = extractTagUserIds()
72259
- // const id = typeChat === 'CHAT' ? chatRoomId : contactId
72260
- // if (id) {
72261
- // connectHub(id, {
72262
- // sendTo: dataInfo.id,
72263
- // content: message.trim(),
72264
- // replyContent: replyMessage?.currentMessage ? JSON.stringify(replyMessage.currentMessage) : null,
72265
- // path: null,
72266
- // type: 'text',
72267
- // typeChat,
72268
- // tagUserIds
72269
- // })
72270
- // }
72271
- // }
72272
- // setImgCopy([])
72273
- // }
72274
- // const uploadWithRetry = async (file: File, maxRetries = 2) => {
72275
- // let lastError
72276
- // for (let attempt = 0; attempt <= maxRetries; attempt++) {
72277
- // try {
72278
- // const formDataFile = new FormData()
72279
- // formDataFile.append('files', file, file.name)
72280
- // const rs = await uploadMultiFileApi(formDataFile).unwrap()
72281
- // return { success: true, data: rs }
72282
- // } catch (error: any) {
72283
- // lastError = error
72284
- // // Không retry nếu là lỗi validation từ server
72285
- // if (error?.status === 400 || error?.status === 413) {
72286
- // break
72287
- // }
72288
- // if (attempt < maxRetries) {
72289
- // // Exponential backoff: 1s, 2s, 4s...
72290
- // await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt))
72291
- // )
72292
- // }
72293
- // }
72294
- // }
72295
- // return {
72296
- // success: false,
72297
- // error: lastError?.message || 'Upload thất bại'
72298
- // }
72299
- // }
72146
+ useCallback((mes) => {
72147
+ setSelectedMessage(mes);
72148
+ setOpenModalPreview(true);
72149
+ }, []);
72150
+ useState(false);
72151
+ useDispatch();
72152
+ //từ đây
72300
72153
  // const sendFile = async (event: any) => {
72301
72154
  // if (event.target.files && event.target.files[0]) {
72302
72155
  // const filesToUpload: File[] = Array.from(event.target.files)