From 31f53d27c164347a48836f068625294e02a97ed9 Mon Sep 17 00:00:00 2001 From: Bruno Windels <274386+bwindels@users.noreply.github.com> Date: Fri, 25 Nov 2022 11:51:22 +0100 Subject: [PATCH] emit update from datetile when date might have changed --- .../session/room/timeline/TilesCollection.js | 14 ++------------ src/domain/session/room/timeline/tiles/DateTile.ts | 5 ++++- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/domain/session/room/timeline/TilesCollection.js b/src/domain/session/room/timeline/TilesCollection.js index e4ed9d24..6652e89c 100644 --- a/src/domain/session/room/timeline/TilesCollection.js +++ b/src/domain/session/room/timeline/TilesCollection.js @@ -151,7 +151,6 @@ export class TilesCollection extends BaseObservableList { } _evaluateDateHeaderAtIdx(tileIdx) { - //console.log("_evaluateDateHeaderAtIdx", tileIdx); // consider two tiles after the inserted tile, because // the first of the two tiles may be a DateTile in which case, // we remove it after looking at the needsDateSeparator prop of the @@ -167,25 +166,16 @@ export class TilesCollection extends BaseObservableList { const tile = this._tiles[idx]; const prevTile = idx > 0 ? this._tiles[idx - 1] : undefined; const hasDateSeparator = prevTile?.shape === TileShape.DateHeader; - if (tile.needsDateSeparator) { - if (hasDateSeparator) { - // TODO: replace this by return UpdateAction from updateNextSibling - // and do this in onAdd - //console.log(" update", idx - 1, prevTile?.shape, prevTile?.eventId); - this.emitUpdate(idx - 1, prevTile, "date"); - } else { - //console.log(" add", idx, tile.shape, tile.eventId); + if (tile.needsDateSeparator && !hasDateSeparator) { // adding a tile shift all the indices we need to consider // especially given we consider removals for the tile that // comes after a datetile tileIdx += 1; this._addTileAt(idx, tile.createDateSeparator()); - } - } else if (hasDateSeparator) { + } else if (!tile.needsDateSeparator && hasDateSeparator) { // this is never triggered because needsDateSeparator is not cleared // when loading more items because we don't do anything once the // direct sibling is a DateTile - //console.log(" remove", idx -1, prevTile?.shape, prevTile?.eventId); this._removeTile(idx - 1, prevTile); } } diff --git a/src/domain/session/room/timeline/tiles/DateTile.ts b/src/domain/session/room/timeline/tiles/DateTile.ts index 92bd42e5..4e7cbda2 100644 --- a/src/domain/session/room/timeline/tiles/DateTile.ts +++ b/src/domain/session/room/timeline/tiles/DateTile.ts @@ -130,8 +130,11 @@ export class DateTile extends ViewModel implements ITile { // TODO: next can be undefined when a pending event is removed // TODO: we need a way to remove this date header this._firstTileInDay = next!; + const prevDateString = this._dateString; this._dateString = undefined; - // TODO: do we need to reevaluate our date here and emit an update? + if (prevDateString && prevDateString !== this.date) { + this._emitUpdate?.(this, "date"); + } } notifyVisible(): void {