From 7cdb6e528f2c5c042e7eb05c6cf7647b5d577b8a Mon Sep 17 00:00:00 2001 From: Bruno Windels <274386+bwindels@users.noreply.github.com> Date: Sat, 25 Jun 2022 12:47:57 +0200 Subject: [PATCH] implement logic when date separator should be shown --- .../session/room/timeline/tiles/SimpleTile.js | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/domain/session/room/timeline/tiles/SimpleTile.js b/src/domain/session/room/timeline/tiles/SimpleTile.js index 09e88113..56c4c002 100644 --- a/src/domain/session/room/timeline/tiles/SimpleTile.js +++ b/src/domain/session/room/timeline/tiles/SimpleTile.js @@ -23,6 +23,7 @@ export class SimpleTile extends ViewModel { super(options); this._entry = entry; this._date = this._entry.timestamp ? new Date(this._entry.timestamp) : null; + this._hasDateSeparator = false; this._emitUpdate = undefined; } // view model props for all subclasses @@ -39,7 +40,25 @@ export class SimpleTile extends ViewModel { } get hasDateSeparator() { - return false; + return this._hasDateSeparator; + } + + _updateDateSeparator(prev) { + let hasDateSeparator; + if (prev instanceof SimpleTile) { + if (prev && prev._date) { + hasDateSeparator = prev._date.getFullYear() !== this._date.getFullYear() || + prev._date.getMonth() !== this._date.getMonth() || + prev._date.getDate() !== this._date.getDate(); + } else { + hasDateSeparator = !!this._date; + } + } else { + hasDateSeparator = true; + } + const changed = hasDateSeparator !== this._hasDateSeparator; + this._hasDateSeparator = hasDateSeparator; + return changed; } get id() { @@ -127,9 +146,12 @@ export class SimpleTile extends ViewModel { tryIncludeEntry() { return false; } - // let item know it has a new sibling - updatePreviousSibling(/*prev*/) { + // let item know it has a new sibling + updatePreviousSibling(prev) { + if (this._updateDateSeparator(prev)) { + this.emitChange(); + } } // let item know it has a new sibling