Strictify Timeline Panel (#11165)

* Get initial fix working

* add a couple of union types to tidy up a bit
pull/28217/head
alunturner 2023-06-30 09:08:35 +01:00 committed by GitHub
parent 3930f1a10b
commit 9fa58e4e90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -591,6 +591,8 @@ class TimelinePanel extends React.Component<IProps, IState> {
const dir = backwards ? EventTimeline.BACKWARDS : EventTimeline.FORWARDS;
const canPaginateKey = backwards ? "canBackPaginate" : "canForwardPaginate";
const paginatingKey = backwards ? "backPaginating" : "forwardPaginating";
type CanPaginateKey = typeof canPaginateKey;
type PaginatingKey = typeof paginatingKey;
if (!this.state[canPaginateKey]) {
debuglog("have given up", dir, "paginating this timeline");
@ -599,7 +601,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
if (!this.timelineWindow?.canPaginate(dir)) {
debuglog("can't", dir, "paginate any further");
this.setState({ [canPaginateKey]: false } as Pick<IState, typeof canPaginateKey>);
this.setState({ [canPaginateKey]: false } as Pick<IState, CanPaginateKey>);
return Promise.resolve(false);
}
@ -609,7 +611,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
}
debuglog("Initiating paginate; backwards:" + backwards);
this.setState({ [paginatingKey]: true } as Pick<IState, typeof paginatingKey>);
this.setState({ [paginatingKey]: true } as Pick<IState, PaginatingKey>);
return this.onPaginationRequest(this.timelineWindow, dir, PAGINATE_SIZE).then(async (r) => {
if (this.unmounted) {
@ -624,13 +626,13 @@ class TimelinePanel extends React.Component<IProps, IState> {
const { events, liveEvents, firstVisibleEventIndex } = this.getEvents();
this.buildLegacyCallEventGroupers(events);
const newState: Partial<IState> = {
const newState = {
[paginatingKey]: false,
[canPaginateKey]: r,
events,
liveEvents,
firstVisibleEventIndex,
};
} as Pick<IState, PaginatingKey | CanPaginateKey | "events" | "liveEvents" | "firstVisibleEventIndex">;
// moving the window in this direction may mean that we can now
// paginate in the other where we previously could not.
@ -647,7 +649,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
// has in memory because we never gave the component a chance to scroll
// itself into the right place
return new Promise((resolve) => {
this.setState<null>(newState, () => {
this.setState(newState, () => {
// we can continue paginating in the given direction if:
// - timelineWindow.paginate says we can
// - we're paginating forwards, or we won't be trying to