Fix live logbook starting empty (#12833)

This commit is contained in:
J. Nick Koston 2022-05-30 19:03:51 -10:00 committed by GitHub
parent ceda911670
commit 077fa3f6b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -310,7 +310,7 @@ export class HaLogbook extends LitElement {
// Put newest ones on top. Reverse works in-place so // Put newest ones on top. Reverse works in-place so
// make a copy first. // make a copy first.
const newEntries = [...streamMessage.events].reverse(); const newEntries = [...streamMessage.events].reverse();
if (!this._logbookEntries) { if (!this._logbookEntries || !this._logbookEntries.length) {
this._logbookEntries = newEntries; this._logbookEntries = newEntries;
return; return;
} }
@ -320,8 +320,10 @@ export class HaLogbook extends LitElement {
return; return;
} }
const nonExpiredRecords = this._nonExpiredRecords(purgeBeforePythonTime); const nonExpiredRecords = this._nonExpiredRecords(purgeBeforePythonTime);
this._logbookEntries = this._logbookEntries = !nonExpiredRecords.length
newEntries[0].when >= this._logbookEntries[0].when ? // All existing entries expired
newEntries
: newEntries[0].when >= nonExpiredRecords[0].when
? // The new records are newer than the old records ? // The new records are newer than the old records
// append the old records to the end of the new records // append the old records to the end of the new records
newEntries.concat(nonExpiredRecords) newEntries.concat(nonExpiredRecords)