don't look at tiles before the inserted tile, there is no need

also clarify with comments how the current algorithm works
This commit is contained in:
Bruno Windels 2022-11-25 11:26:53 +01:00
parent d889c7deeb
commit 4abf18a5f1
2 changed files with 11 additions and 4 deletions

View File

@ -152,9 +152,11 @@ export class TilesCollection extends BaseObservableList {
_evaluateDateHeaderAtIdx(tileIdx) {
//console.log("_evaluateDateHeaderAtIdx", tileIdx);
// consider the two adjacent tiles where the previous sibling changed:
// the new tile and the next tile
for (let i = -2; i < 3; i += 1) {
// 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
// next next tile
for (let i = 0; i < 2; i += 1) {
const idx = tileIdx + i;
if (idx < 0) {
continue;
@ -173,10 +175,12 @@ export class TilesCollection extends BaseObservableList {
this.emitUpdate(idx - 1, prevTile, "date");
} else {
//console.log(" add", idx, tile.shape, tile.eventId);
// 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());
}
// TODO must be looking at the wrong index to find the old date separator??
} else if (hasDateSeparator) {
// this is never triggered because needsDateSeparator is not cleared
// when loading more items because we don't do anything once the

View File

@ -119,6 +119,9 @@ export class DateTile extends ViewModel implements ITile<BaseEventEntry> {
// let item know it has a new sibling
updatePreviousSibling(prev: ITile<BaseEntry> | undefined): void {
// forward the sibling update to our next tile, so it is informed
// about it's previous sibling beyond the date header (which is it's direct previous sibling)
// so it can recalculate whether it still needs a date header
this._firstTileInDay.updatePreviousSibling(prev);
}