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