@esvndev/es-react-template-chat 0.0.89 → 0.0.90
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 +172 -197
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +172 -197
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -72070,7 +72070,7 @@ const ChatLog = (props) => {
|
|
|
72070
72070
|
const { typeChat, contactId, chatRoomId, active, messageByGroup, pinnedMessages, setScroll, checkScroll, pinMessageChatRoom, deleteMessageApi, recallMessageApi, get_message_by_group_cursor_api, getPinMessageChatRoomApi, deletePinMessage,
|
|
72071
72071
|
//updateGroupTagApi,
|
|
72072
72072
|
createReminderApi, senMessageApi, typingUsers } = useChat();
|
|
72073
|
-
configureStore.useAppSelector((state) => state.hubNotification);
|
|
72073
|
+
const { connection } = configureStore.useAppSelector((state) => state.hubNotification);
|
|
72074
72074
|
const [dynamicMenuItems, setDynamicMenuItems] = React.useState([]);
|
|
72075
72075
|
React.useEffect(() => {
|
|
72076
72076
|
const fetchFormConfig = async () => {
|
|
@@ -72111,38 +72111,68 @@ const ChatLog = (props) => {
|
|
|
72111
72111
|
], [dynamicMenuItems]);
|
|
72112
72112
|
// Menu items cho Hành chính (chỉ administrative)
|
|
72113
72113
|
React.useMemo(() => ADMINISTRATIVE_ITEMS, []);
|
|
72114
|
-
React.useRef(false);
|
|
72115
|
-
React.useRef(null);
|
|
72116
|
-
React.useRef(null);
|
|
72114
|
+
const isTypingRef = React.useRef(false);
|
|
72115
|
+
const typingTimeoutRef = React.useRef(null);
|
|
72117
72116
|
React.useRef(null);
|
|
72118
72117
|
React.useRef(null);
|
|
72118
|
+
const inputContainer = React.useRef(null);
|
|
72119
72119
|
const containerChatRef = React.useRef(null);
|
|
72120
72120
|
const { connectHub, dataInfo, dataProfile, handleUser, handleUserSidebarRight, handleSidebar, handleSidebarRight, userSidebarLeft, dataHistory, chatGetType, approveUpdateStatus, handleModalAdministrative, setDataItem, handleModalAddUserGroup, handleModalGroup, typeOpenModalAdd, setTypeOpenModalAdd, unpinMessage, getPinnedMessages } = props;
|
|
72121
72121
|
const groupChatUsers = dataHistory?.find((dt) => dt.id === active);
|
|
72122
72122
|
//const dataInfoAvatar = dataInfo && dataInfo.avatar ? dataInfo.avatar : DEFAULT_AVATAR
|
|
72123
|
-
React.useState([]);
|
|
72124
|
-
React.useState(false);
|
|
72123
|
+
const [imgCopy, setImgCopy] = React.useState([]);
|
|
72124
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
72125
72125
|
const [openModalPreview, setOpenModalPreview] = React.useState(false);
|
|
72126
72126
|
React.useState(false);
|
|
72127
72127
|
React.useState(false);
|
|
72128
72128
|
React.useState(false);
|
|
72129
72129
|
React.useState('');
|
|
72130
72130
|
React.useState(null);
|
|
72131
|
-
React.useState(null);
|
|
72132
|
-
React.useState(null);
|
|
72133
|
-
React.useState({ x: 0, y: 0 });
|
|
72134
|
-
React.useState(undefined);
|
|
72135
|
-
React.useState(undefined);
|
|
72131
|
+
const [currentMessage, setCurrentMessage] = React.useState(null);
|
|
72132
|
+
const [replyMessage, setReplyMessage] = React.useState(null);
|
|
72133
|
+
const [position, setPosition] = React.useState({ x: 0, y: 0 });
|
|
72134
|
+
const [listContextShow, setListContextShow] = React.useState(undefined);
|
|
72135
|
+
const [listContextHide, setListContextHide] = React.useState(undefined);
|
|
72136
72136
|
const [selectedMessage, setSelectedMessage] = React.useState(null);
|
|
72137
|
-
React.useState(false);
|
|
72138
|
-
React.useState(true);
|
|
72139
|
-
React.useRef(0);
|
|
72137
|
+
const [isMultiLine, setIsMultiLine] = React.useState(false);
|
|
72138
|
+
const [isAtBottom, setIsAtBottom] = React.useState(true);
|
|
72139
|
+
const prevListLength = React.useRef(0);
|
|
72140
72140
|
React.useState(0);
|
|
72141
72141
|
React.useState(true);
|
|
72142
72142
|
React.useState(new Set());
|
|
72143
|
-
React.useState(null);
|
|
72143
|
+
const [clickedImageFile, setClickedImageFile] = React.useState(null);
|
|
72144
72144
|
React.useState(false);
|
|
72145
72145
|
React.useState(new Set());
|
|
72146
|
+
const BASE_CONTEXT_ITEMS = [
|
|
72147
|
+
"reply", "share", "pin", "bookmark",
|
|
72148
|
+
"selectMultiMessage", "detail", "other", "recall", "delete"
|
|
72149
|
+
];
|
|
72150
|
+
const CONTEXT_CONFIG = {
|
|
72151
|
+
selection: {
|
|
72152
|
+
show: ["copyRangeText", ...BASE_CONTEXT_ITEMS, "save"],
|
|
72153
|
+
hide: ["copyText", "save", "copyImage"]
|
|
72154
|
+
},
|
|
72155
|
+
image: {
|
|
72156
|
+
show: ["copyImage", ...BASE_CONTEXT_ITEMS, "save"],
|
|
72157
|
+
hide: ["copyText", "copyRangeText"]
|
|
72158
|
+
},
|
|
72159
|
+
file: {
|
|
72160
|
+
show: [...BASE_CONTEXT_ITEMS, "save"],
|
|
72161
|
+
hide: ["copyText", "copyRangeText", "copyImage"]
|
|
72162
|
+
},
|
|
72163
|
+
text: {
|
|
72164
|
+
show: ["copyText", ...BASE_CONTEXT_ITEMS],
|
|
72165
|
+
hide: ["copyRangeText", "save", "copyImage"]
|
|
72166
|
+
},
|
|
72167
|
+
voucher: {
|
|
72168
|
+
show: ["copyText", ...BASE_CONTEXT_ITEMS],
|
|
72169
|
+
hide: ["copyRangeText", "save", "copyImage"]
|
|
72170
|
+
},
|
|
72171
|
+
default: {
|
|
72172
|
+
show: ["copyText", ...BASE_CONTEXT_ITEMS],
|
|
72173
|
+
hide: ["copyRangeText", "save", "copyImage"]
|
|
72174
|
+
}
|
|
72175
|
+
};
|
|
72146
72176
|
React.useState(true);
|
|
72147
72177
|
const scrollToBottom = () => {
|
|
72148
72178
|
const messagesEndEle = document.getElementById('messagesEnd');
|
|
@@ -72178,188 +72208,133 @@ const ChatLog = (props) => {
|
|
|
72178
72208
|
}, []);
|
|
72179
72209
|
React.useState(false);
|
|
72180
72210
|
reactRedux.useDispatch();
|
|
72181
|
-
|
|
72182
|
-
|
|
72183
|
-
|
|
72184
|
-
|
|
72185
|
-
|
|
72186
|
-
|
|
72187
|
-
|
|
72188
|
-
|
|
72189
|
-
|
|
72190
|
-
|
|
72191
|
-
|
|
72192
|
-
|
|
72193
|
-
|
|
72194
|
-
|
|
72195
|
-
|
|
72196
|
-
|
|
72197
|
-
|
|
72198
|
-
|
|
72199
|
-
|
|
72200
|
-
|
|
72201
|
-
|
|
72202
|
-
|
|
72203
|
-
|
|
72204
|
-
|
|
72205
|
-
|
|
72206
|
-
|
|
72207
|
-
|
|
72208
|
-
|
|
72209
|
-
|
|
72210
|
-
|
|
72211
|
-
|
|
72212
|
-
|
|
72213
|
-
|
|
72214
|
-
|
|
72215
|
-
|
|
72216
|
-
|
|
72217
|
-
|
|
72218
|
-
|
|
72219
|
-
|
|
72220
|
-
|
|
72221
|
-
|
|
72222
|
-
|
|
72223
|
-
|
|
72224
|
-
|
|
72225
|
-
|
|
72226
|
-
|
|
72227
|
-
|
|
72228
|
-
|
|
72229
|
-
|
|
72230
|
-
|
|
72231
|
-
|
|
72232
|
-
|
|
72233
|
-
|
|
72234
|
-
|
|
72235
|
-
|
|
72236
|
-
|
|
72237
|
-
|
|
72238
|
-
|
|
72239
|
-
|
|
72240
|
-
|
|
72241
|
-
|
|
72242
|
-
|
|
72243
|
-
|
|
72244
|
-
|
|
72245
|
-
|
|
72246
|
-
|
|
72247
|
-
|
|
72248
|
-
|
|
72249
|
-
|
|
72250
|
-
|
|
72251
|
-
//
|
|
72252
|
-
|
|
72253
|
-
|
|
72254
|
-
|
|
72255
|
-
|
|
72256
|
-
|
|
72257
|
-
|
|
72258
|
-
|
|
72259
|
-
|
|
72260
|
-
|
|
72261
|
-
|
|
72262
|
-
|
|
72263
|
-
|
|
72264
|
-
|
|
72265
|
-
|
|
72266
|
-
|
|
72267
|
-
|
|
72268
|
-
|
|
72269
|
-
|
|
72270
|
-
|
|
72271
|
-
|
|
72272
|
-
|
|
72273
|
-
|
|
72274
|
-
|
|
72275
|
-
|
|
72276
|
-
|
|
72277
|
-
|
|
72278
|
-
|
|
72279
|
-
|
|
72280
|
-
|
|
72281
|
-
|
|
72282
|
-
|
|
72283
|
-
|
|
72284
|
-
|
|
72285
|
-
|
|
72286
|
-
|
|
72287
|
-
|
|
72288
|
-
|
|
72289
|
-
|
|
72290
|
-
|
|
72291
|
-
|
|
72292
|
-
|
|
72293
|
-
|
|
72294
|
-
|
|
72295
|
-
|
|
72296
|
-
|
|
72297
|
-
|
|
72298
|
-
|
|
72299
|
-
|
|
72300
|
-
|
|
72301
|
-
|
|
72302
|
-
|
|
72303
|
-
|
|
72304
|
-
|
|
72305
|
-
|
|
72306
|
-
|
|
72307
|
-
|
|
72308
|
-
// //chatRoomId,
|
|
72309
|
-
// //chatGetType
|
|
72310
|
-
// ])
|
|
72311
|
-
// // Chuyển phòng thì load lại message + pinned messages
|
|
72312
|
-
// useEffect(() => {
|
|
72313
|
-
// if (!chatRoomId && handleSidebar) { return }
|
|
72314
|
-
// chatGetType(chatRoomId, undefined, "", "", undefined, undefined, 0, 0)
|
|
72315
|
-
// if (chatRoomId) {
|
|
72316
|
-
// getPinMessageChatRoomApi(chatRoomId)
|
|
72317
|
-
// }
|
|
72318
|
-
// }, [chatRoomId])
|
|
72319
|
-
// const handleUnpinMessage = useCallback(async (message: any) => {
|
|
72320
|
-
// const pinId = message?.pinId || message?.id
|
|
72321
|
-
// if (!pinId) { return }
|
|
72322
|
-
// await deletePinMessage(pinId)
|
|
72323
|
-
// }, [deletePinMessage, chatRoomId])
|
|
72324
|
-
// const handleViewPinnedMessage = useCallback((message: any) => {
|
|
72325
|
-
// if (message?.id) {
|
|
72326
|
-
// //setViewingPinnedMessage(message.id)
|
|
72327
|
-
// // Tìm message element
|
|
72328
|
-
// const element = document.getElementById(`msg-${message.id}`)
|
|
72329
|
-
// const chatContainer = document.getElementById('scrollableDivChat')
|
|
72330
|
-
// if (element && chatContainer) {
|
|
72331
|
-
// // Lấy vị trí của element và container
|
|
72332
|
-
// const elementRect = element.getBoundingClientRect()
|
|
72333
|
-
// const containerRect = chatContainer.getBoundingClientRect()
|
|
72334
|
-
// // Tính toán scroll position để đưa element vào giữa container
|
|
72335
|
-
// const scrollTop = chatContainer.scrollTop
|
|
72336
|
-
// const offset = elementRect.top - containerRect.top - (containerRect.height / 2) + (elementRect.height / 2)
|
|
72337
|
-
// // Scroll trong container, không scroll toàn page
|
|
72338
|
-
// chatContainer.scrollTo({
|
|
72339
|
-
// top: scrollTop + offset,
|
|
72340
|
-
// behavior: 'smooth'
|
|
72341
|
-
// })
|
|
72342
|
-
// // Highlight message
|
|
72343
|
-
// const originalBg = element.style.backgroundColor
|
|
72344
|
-
// const originalZIndex = element.style.zIndex
|
|
72345
|
-
// element.style.backgroundColor = '#fff3cd'
|
|
72346
|
-
// element.style.zIndex = '1000'
|
|
72347
|
-
// element.style.position = 'relative'
|
|
72348
|
-
// element.style.transition = 'background-color 0.3s'
|
|
72349
|
-
// // Auto close sau 500ms
|
|
72350
|
-
// setTimeout(() => {
|
|
72351
|
-
// element.style.backgroundColor = originalBg || ''
|
|
72352
|
-
// element.style.zIndex = originalZIndex || ''
|
|
72353
|
-
// //setViewingPinnedMessage(null)
|
|
72354
|
-
// }, 500)
|
|
72355
|
-
// } else {
|
|
72356
|
-
// console.log('Message not found in current view, may need to load more messages')
|
|
72357
|
-
// setTimeout(() => {
|
|
72358
|
-
// //setViewingPinnedMessage(null)
|
|
72359
|
-
// }, 2000)
|
|
72360
|
-
// }
|
|
72361
|
-
// }
|
|
72362
|
-
// }, [])
|
|
72211
|
+
React.useCallback((idx) => {
|
|
72212
|
+
const newArr = [...imgCopy];
|
|
72213
|
+
newArr.splice(idx, 1);
|
|
72214
|
+
setImgCopy(newArr);
|
|
72215
|
+
}, [imgCopy]);
|
|
72216
|
+
React.useCallback((e, chatMessage) => {
|
|
72217
|
+
const selection = window.document.getSelection();
|
|
72218
|
+
setIsOpen(true);
|
|
72219
|
+
setPosition({ x: e.clientX, y: e.clientY });
|
|
72220
|
+
if (e.target) {
|
|
72221
|
+
setCurrentMessage(chatMessage);
|
|
72222
|
+
}
|
|
72223
|
+
// Detect ảnh được click từ data attribute
|
|
72224
|
+
const fileIndex = e.target?.dataset?.fileIndex;
|
|
72225
|
+
if (fileIndex !== undefined && chatMessage?.path) {
|
|
72226
|
+
setClickedImageFile(chatMessage.path[parseInt(fileIndex)]);
|
|
72227
|
+
}
|
|
72228
|
+
else {
|
|
72229
|
+
setClickedImageFile(null);
|
|
72230
|
+
}
|
|
72231
|
+
e.preventDefault();
|
|
72232
|
+
const contextType = selection.toString() ? 'selection' : chatMessage?.type ? chatMessage.type : 'default';
|
|
72233
|
+
const config = CONTEXT_CONFIG[contextType];
|
|
72234
|
+
setListContextShow({ list: config.show, type: "SHOW" });
|
|
72235
|
+
setListContextHide({ list: config.hide, type: "HIDE" });
|
|
72236
|
+
}, []);
|
|
72237
|
+
const handleTypingStart = () => {
|
|
72238
|
+
if (!isTypingRef.current && connection && chatRoomId) {
|
|
72239
|
+
connection.invoke('StartTyping', chatRoomId).catch(console.error);
|
|
72240
|
+
isTypingRef.current = true;
|
|
72241
|
+
}
|
|
72242
|
+
};
|
|
72243
|
+
const handleTypingStop = () => {
|
|
72244
|
+
if (typingTimeoutRef.current) {
|
|
72245
|
+
clearTimeout(typingTimeoutRef.current);
|
|
72246
|
+
}
|
|
72247
|
+
typingTimeoutRef.current = setTimeout(() => {
|
|
72248
|
+
if (isTypingRef.current && connection && chatRoomId) {
|
|
72249
|
+
connection.invoke('StopTyping', chatRoomId).catch(console.error);
|
|
72250
|
+
isTypingRef.current = false;
|
|
72251
|
+
}
|
|
72252
|
+
}, 2000);
|
|
72253
|
+
};
|
|
72254
|
+
React.useCallback((editorState) => {
|
|
72255
|
+
if (inputContainer &&
|
|
72256
|
+
inputContainer.current &&
|
|
72257
|
+
inputContainer.current.clientHeight > 50) {
|
|
72258
|
+
setIsMultiLine(true);
|
|
72259
|
+
}
|
|
72260
|
+
else {
|
|
72261
|
+
setIsMultiLine(false);
|
|
72262
|
+
}
|
|
72263
|
+
editorState.read(() => {
|
|
72264
|
+
handleTypingStart();
|
|
72265
|
+
handleTypingStop();
|
|
72266
|
+
});
|
|
72267
|
+
}, [inputContainer, connection, chatRoomId]);
|
|
72268
|
+
React.useEffect(() => {
|
|
72269
|
+
if (active) {
|
|
72270
|
+
setReplyMessage(null);
|
|
72271
|
+
setImgCopy([]);
|
|
72272
|
+
setIsAtBottom(true);
|
|
72273
|
+
prevListLength.current = 0;
|
|
72274
|
+
}
|
|
72275
|
+
}, [
|
|
72276
|
+
active,
|
|
72277
|
+
dataInfo
|
|
72278
|
+
//chatRoomId,
|
|
72279
|
+
//chatGetType
|
|
72280
|
+
]);
|
|
72281
|
+
// Chuyển phòng thì load lại message + pinned messages
|
|
72282
|
+
React.useEffect(() => {
|
|
72283
|
+
if (!chatRoomId && handleSidebar) {
|
|
72284
|
+
return;
|
|
72285
|
+
}
|
|
72286
|
+
chatGetType(chatRoomId, undefined, "", "", undefined, undefined, 0, 0);
|
|
72287
|
+
if (chatRoomId) {
|
|
72288
|
+
getPinMessageChatRoomApi(chatRoomId);
|
|
72289
|
+
}
|
|
72290
|
+
}, [chatRoomId]);
|
|
72291
|
+
React.useCallback(async (message) => {
|
|
72292
|
+
const pinId = message?.pinId || message?.id;
|
|
72293
|
+
if (!pinId) {
|
|
72294
|
+
return;
|
|
72295
|
+
}
|
|
72296
|
+
await deletePinMessage(pinId);
|
|
72297
|
+
}, [deletePinMessage, chatRoomId]);
|
|
72298
|
+
React.useCallback((message) => {
|
|
72299
|
+
if (message?.id) {
|
|
72300
|
+
//setViewingPinnedMessage(message.id)
|
|
72301
|
+
// Tìm message element
|
|
72302
|
+
const element = document.getElementById(`msg-${message.id}`);
|
|
72303
|
+
const chatContainer = document.getElementById('scrollableDivChat');
|
|
72304
|
+
if (element && chatContainer) {
|
|
72305
|
+
// Lấy vị trí của element và container
|
|
72306
|
+
const elementRect = element.getBoundingClientRect();
|
|
72307
|
+
const containerRect = chatContainer.getBoundingClientRect();
|
|
72308
|
+
// Tính toán scroll position để đưa element vào giữa container
|
|
72309
|
+
const scrollTop = chatContainer.scrollTop;
|
|
72310
|
+
const offset = elementRect.top - containerRect.top - (containerRect.height / 2) + (elementRect.height / 2);
|
|
72311
|
+
// Scroll trong container, không scroll toàn page
|
|
72312
|
+
chatContainer.scrollTo({
|
|
72313
|
+
top: scrollTop + offset,
|
|
72314
|
+
behavior: 'smooth'
|
|
72315
|
+
});
|
|
72316
|
+
// Highlight message
|
|
72317
|
+
const originalBg = element.style.backgroundColor;
|
|
72318
|
+
const originalZIndex = element.style.zIndex;
|
|
72319
|
+
element.style.backgroundColor = '#fff3cd';
|
|
72320
|
+
element.style.zIndex = '1000';
|
|
72321
|
+
element.style.position = 'relative';
|
|
72322
|
+
element.style.transition = 'background-color 0.3s';
|
|
72323
|
+
// Auto close sau 500ms
|
|
72324
|
+
setTimeout(() => {
|
|
72325
|
+
element.style.backgroundColor = originalBg || '';
|
|
72326
|
+
element.style.zIndex = originalZIndex || '';
|
|
72327
|
+
//setViewingPinnedMessage(null)
|
|
72328
|
+
}, 500);
|
|
72329
|
+
}
|
|
72330
|
+
else {
|
|
72331
|
+
console.log('Message not found in current view, may need to load more messages');
|
|
72332
|
+
setTimeout(() => {
|
|
72333
|
+
//setViewingPinnedMessage(null)
|
|
72334
|
+
}, 2000);
|
|
72335
|
+
}
|
|
72336
|
+
}
|
|
72337
|
+
}, []);
|
|
72363
72338
|
// const onKeyDown = (event: any) => {
|
|
72364
72339
|
// if (event.code === 'NumpadEnter') {
|
|
72365
72340
|
// event.preventDefault()
|