Skip to content

Commit

Permalink
improve chat load
Browse files Browse the repository at this point in the history
  • Loading branch information
Philreact committed Nov 14, 2024
1 parent 7cee886 commit baabe65
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/components/Chat/ChatDirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ const clearEditorContent = () => {

const onReply = useCallback((message)=> {
setReplyMessage(message)
editorRef?.current?.chain().focus()

}, [])


Expand Down
48 changes: 28 additions & 20 deletions src/components/Chat/ChatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,32 +108,40 @@ export const ChatList = ({ initialMessages, myAddress, tempMessages, chatId, onR
getScrollElement: () => parentRef.current,
estimateSize: () => 80, // Provide an estimated height of items, adjust this as needed
overscan: 10, // Number of items to render outside the visible area to improve smoothness
measureElement:
typeof window !== 'undefined' &&
navigator.userAgent.indexOf('Firefox') === -1
? element => {
return element?.getBoundingClientRect().height
}
: undefined,
getItemKey: React.useCallback(
(index) => messages[index].signature,
[messages]
),
});

return (
<div style={{
height: '100%',
position: 'relative'
position: 'relative',
display: 'flex',
flexDirection: 'column'
}}>
<div ref={parentRef} style={{ height: '100%', overflow: 'auto', position: 'relative', display: 'flex' }}>
<div
style={{
width: '100%',
position: 'relative',
display: 'flex',
flexDirection: 'column',
alignItems: 'center', // Center items horizontally
gap: '10px', // Add gap between items
flexGrow: 1
}}
<div
ref={parentRef}
className="List"
style={{ flexGrow: 1, overflow: 'auto', position: 'relative', display: 'flex', height: '0px' }}
>
<div
style={{
height: rowVirtualizer.getTotalSize(),
width: '100%',

}}
>
<div
style={{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
// transform: `translateY(${rowVirtualizer.getVirtualItems()[0]?.start ?? 0}px)`,
}}
>
{rowVirtualizer.getVirtualItems().map((virtualRow) => {
const index = virtualRow.index;
let message = messages[index];
Expand Down Expand Up @@ -205,7 +213,7 @@ export const ChatList = ({ initialMessages, myAddress, tempMessages, chatId, onR
);
})}
</div>

</div>

</div>
{showScrollButton && (
Expand Down

0 comments on commit baabe65

Please sign in to comment.