From 7c6d651b32a79159dae0c313d18606329f4f2118 Mon Sep 17 00:00:00 2001 From: Bruno Windels <274386+bwindels@users.noreply.github.com> Date: Fri, 25 Nov 2022 12:09:28 +0100 Subject: [PATCH] remove date headers when removing pending tiles --- src/domain/session/room/timeline/TilesCollection.js | 4 ++++ src/domain/session/room/timeline/tiles/DateTile.ts | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/domain/session/room/timeline/TilesCollection.js b/src/domain/session/room/timeline/TilesCollection.js index c9a9d6df..95eac7ac 100644 --- a/src/domain/session/room/timeline/TilesCollection.js +++ b/src/domain/session/room/timeline/TilesCollection.js @@ -255,6 +255,10 @@ export class TilesCollection extends BaseObservableList { this.emitRemove(tileIdx, tile); prevTile?.updateNextSibling(nextTile); nextTile?.updatePreviousSibling(prevTile); + + if (prevTile && prevTile.shape === TileShape.DateHeader && (!nextTile || !nextTile.needsDateSeparator)) { + this._removeTile(tileIdx - 1, prevTile); + } } // would also be called when unloading a part of the timeline diff --git a/src/domain/session/room/timeline/tiles/DateTile.ts b/src/domain/session/room/timeline/tiles/DateTile.ts index 4e7cbda2..7e860511 100644 --- a/src/domain/session/room/timeline/tiles/DateTile.ts +++ b/src/domain/session/room/timeline/tiles/DateTile.ts @@ -127,9 +127,14 @@ export class DateTile extends ViewModel implements ITile { // let item know it has a new sibling updateNextSibling(next: ITile | undefined): UpdateAction { - // TODO: next can be undefined when a pending event is removed - // TODO: we need a way to remove this date header - this._firstTileInDay = next!; + if(!next) { + // If we are the DateTile for the last tile in the timeline, + // and that tile gets removed, next would be undefined + // and this DateTile would be removed as well, + // so do nothing + return; + } + this._firstTileInDay = next; const prevDateString = this._dateString; this._dateString = undefined; if (prevDateString && prevDateString !== this.date) {