Skip to content

Commit

Permalink
make it work, still has following bugs:
Browse files Browse the repository at this point in the history
- huge messages
	bvaughn/react-virtualized#610
- doesn't start at bottom
- image height
- context menu missing
- scrolling is lagging (throws you forward and backwards a bit while scrolling)
- and likely even more bugs
  • Loading branch information
Simon-Laux committed May 28, 2020
1 parent 043e902 commit a7d3b40
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
2 changes: 2 additions & 0 deletions scss/message/_message-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
min-width: 200px;

li {
margin-left: 5px;
margin-right: 5px;
margin-bottom: 10px;
min-width: 200px;

Expand Down
51 changes: 30 additions & 21 deletions src/renderer/components/message/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ export default function MessageList({
const heightCache = useRef(
new CellMeasurerCache({
fixedWidth: true,
defaultHeight: 60,
defaultHeight: 79,
minHeight: 25,
})
)

useEffect(() => heightCache.current.clearAll(), [chat.id])
useKeyBindingAction(KeybindAction.Event_Window_Resize, () =>
heightCache.current.clearAll()
)
Expand Down Expand Up @@ -64,11 +63,16 @@ export default function MessageList({
Scroller.current?.scrollToRow(messageIds.length)
})

useEffect(() => {
heightCache.current.clearAll()
Loader.current.resetLoadMoreRowsCache()
}, [chat.id])

return (
<div className='message-list' style={{ height: '100%' }}>
<AutoSizer>
{({ width, height }) => (
<ul style={{ margin: 0 }}>
<ul style={{ margin: 0, width }}>
{messageIds.length < 1 && (
<li key={'empty-chat-message'}>
<div className='info-message big'>
Expand All @@ -92,11 +96,13 @@ export default function MessageList({
registerChild(ref)
}}
onRowsRendered={onRowsRendered}
overscanRowCount={10}
height={height}
width={width}
scrollToIndex={messageIds.length - 1}
rowCount={messageIds.length}
rowHeight={heightCache.current.rowHeight}
rowRenderer={({ key, index, parent }) => {
rowRenderer={({ key, index, parent, style }) => {
console.log('rowRenderer', index, messageIds[index])
const msgId = messageIds[index]

Expand All @@ -111,17 +117,19 @@ export default function MessageList({
parent={parent}
rowIndex={index}
>
<div className='info-message' key={key}>
<p style={{ textTransform: 'capitalize' }}>
{moment
.unix(nextMessage.msg.timestamp)
.calendar(null, {
sameDay: `[${tx('today')}]`,
lastDay: `[${tx('yesterday')}]`,
lastWeek: 'LL',
sameElse: 'LL',
})}
</p>
<div style={style}>
<div className='info-message' key={key}>
<p style={{ textTransform: 'capitalize' }}>
{moment
.unix(nextMessage.msg.timestamp)
.calendar(null, {
sameDay: `[${tx('today')}]`,
lastDay: `[${tx('yesterday')}]`,
lastWeek: 'LL',
sameElse: 'LL',
})}
</p>
</div>
</div>
</CellMeasurer>
)
Expand All @@ -136,12 +144,13 @@ export default function MessageList({
parent={parent}
rowIndex={index}
>
<MessageWrapper
key={key}
message={message as MessageType}
locationStreamingEnabled={locationStreamingEnabled}
chat={chat}
/>
<div style={style}>
<MessageWrapper
message={message as MessageType}
locationStreamingEnabled={locationStreamingEnabled}
chat={chat}
/>
</div>
</CellMeasurer>
)
}}
Expand Down

0 comments on commit a7d3b40

Please sign in to comment.