Fix history view

This commit is contained in:
Andras Schmelczer 2025-03-23 15:00:20 +00:00
parent 58a61d036b
commit 468d0ac8cf
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
4 changed files with 77 additions and 45 deletions

View file

@ -70,7 +70,7 @@
textarea {
resize: none;
height: 60px;
height: 75px;
}
}

View file

@ -23,11 +23,14 @@ export class HistoryView extends ItemView {
super(leaf);
this.icon = HistoryView.ICON;
this.client.addSyncHistoryUpdateListener(() => {
this.updateView().catch((_error: unknown) => {
this.client.logger.error("Failed to update history view");
});
});
this.client.addSyncHistoryUpdateListener(
() =>
void this.updateView().catch((error: unknown) => {
this.client.logger.error(
`Failed to update history view: ${error}`
);
})
);
}
private static getSyncTypeIcon(type: SyncType | undefined): IconName {
@ -58,6 +61,21 @@ export class HistoryView extends ItemView {
});
}
private static updateTimeSince(
element: HTMLElement,
entry: HistoryEntry
): void {
const timestampElement = element.querySelector(
".history-card-timestamp"
);
if (timestampElement != null) {
timestampElement.textContent = intlFormatDistance(
entry.timestamp,
new Date()
);
}
}
public getViewType(): string {
return HistoryView.TYPE;
}
@ -88,7 +106,7 @@ export class HistoryView extends ItemView {
return;
}
const entries = this.client.getHistoryEntries().reverse();
const entries = this.client.getHistoryEntries();
if (this.historyEntryToElement.size === 0 && entries.length > 0) {
// Clear the "No update has happened yet" message
@ -98,15 +116,7 @@ export class HistoryView extends ItemView {
entries.forEach((entry) => {
const element = this.historyEntryToElement.get(entry);
if (element !== undefined) {
const timestampElement = element.querySelector(
".history-card-timestamp"
);
if (timestampElement != null) {
timestampElement.textContent = intlFormatDistance(
entry.timestamp,
new Date()
);
}
HistoryView.updateTimeSince(element, entry);
return;
}