Skip to content

Commit

Permalink
fix performance hit that the date header had
Browse files Browse the repository at this point in the history
because of the state updates it triggered videos did flash/flicker/reload while scrolling
  • Loading branch information
Simon-Laux committed Sep 28, 2023
1 parent e497146 commit aa8f480
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/renderer/components/Gallery.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ChangeEvent, Component } from 'react'
import React, { ChangeEvent, Component, createRef } from 'react'
import { ScreenContext } from '../contexts'
import {
AudioAttachment,
Expand All @@ -14,7 +14,7 @@ import { selectedAccountId } from '../ScreenController'
import AutoSizer from 'react-virtualized-auto-sizer'
import { FixedSizeGrid } from 'react-window'
import SettingsStoreInstance, { SettingsStoreState } from '../stores/settings'
import moment, { Moment } from 'moment'
import moment from 'moment'

const log = getLogger('renderer/Gallery')

Expand Down Expand Up @@ -63,9 +63,9 @@ export default class Gallery extends Component<
loading: boolean
queryText: string
GalleryImageKeepAspectRatio?: boolean
dateMoment?: Moment
}
> {
dateHeader = createRef<HTMLDivElement>()
constructor(props: mediaProps) {
super(props)
this.state = {
Expand All @@ -77,7 +77,6 @@ export default class Gallery extends Component<
loading: true,
queryText: '',
GalleryImageKeepAspectRatio: false,
dateMoment: undefined,
}

this.settingsStoreListener = this.settingsStoreListener.bind(this)
Expand All @@ -92,7 +91,6 @@ export default class Gallery extends Component<
mediaLoadResult: {},
loading: true,
queryText: '',
dateMoment: undefined,
})
}

Expand Down Expand Up @@ -152,7 +150,6 @@ export default class Gallery extends Component<
mediaMessageIds: media_ids,
mediaLoadResult,
loading: false,
dateMoment: undefined,
})
this.forceUpdate()
})
Expand Down Expand Up @@ -182,9 +179,10 @@ export default class Gallery extends Component<

updateFirstVisibleMessage(message: Type.MessageLoadResult) {
if (message.variant === 'message') {
this.setState({
dateMoment: moment(message.timestamp * 1000),
})
if (this.dateHeader.current)
this.dateHeader.current.innerText = moment(
message.timestamp * 1000
).format('LL')
}
}

Expand Down Expand Up @@ -233,10 +231,8 @@ export default class Gallery extends Component<
</li>
)
})}
{showDateHeader && this.state.dateMoment && (
<div className='big-date'>
{this.state.dateMoment.format('LL')}
</div>
{showDateHeader && (
<div className='big-date' ref={this.dateHeader}></div>
)}
</ul>
<div role='tabpanel'>
Expand Down

0 comments on commit aa8f480

Please sign in to comment.