Improve history view UX

This commit is contained in:
Andras Schmelczer 2025-05-24 19:05:12 +01:00
commit f93ca447d8
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
2 changed files with 42 additions and 14 deletions

View file

@ -17,6 +17,10 @@
background-color: rgba(var(--color-red-rgb), 0.2); background-color: rgba(var(--color-red-rgb), 0.2);
} }
&.skipped {
background-color: rgba(var(--color-green-rgb), 0.08);
}
.history-card-header { .history-card-header {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@ -36,6 +40,10 @@
gap: var(--size-4-2); gap: var(--size-4-2);
word-break: break-all; word-break: break-all;
margin: 0; margin: 0;
> span {
margin-bottom: var(--size-4-1);
}
} }
.history-card-timestamp { .history-card-timestamp {

View file

@ -42,6 +42,10 @@ export class HistoryView extends ItemView {
return "trash-2"; return "trash-2";
case SyncType.UPDATE: case SyncType.UPDATE:
return "file-pen-line"; return "file-pen-line";
case SyncType.MOVE:
return "move-right";
case SyncType.SKIPPED:
return "circle-slash";
case undefined: case undefined:
default: default:
return ""; return "";
@ -52,13 +56,17 @@ export class HistoryView extends ItemView {
element: HTMLElement, element: HTMLElement,
entry: HistoryEntry entry: HistoryEntry
): void { ): void {
const syncTypeIcon = HistoryView.getSyncTypeIcon(entry.type); const syncTypeIcon = HistoryView.getSyncTypeIcon(entry.details.type);
if (syncTypeIcon) { if (syncTypeIcon) {
setIcon(element.createDiv(), syncTypeIcon); setIcon(element.createDiv(), syncTypeIcon);
} }
const fileName = entry.details.relativePath.split("/").pop();
element.createEl("span", { element.createEl("span", {
text: entry.relativePath.split("/").pop() text:
entry.details.type === SyncType.SKIPPED
? `Skipped: ${fileName}`
: fileName
}); });
} }
@ -69,14 +77,21 @@ export class HistoryView extends ItemView {
const timestampElement = element.querySelector( const timestampElement = element.querySelector(
".history-card-timestamp" ".history-card-timestamp"
); );
if (timestampElement != null) { if (timestampElement != null) {
timestampElement.textContent = intlFormatDistance( timestampElement.textContent =
entry.timestamp, HistoryView.getTimestampAndAuthor(entry);
new Date()
);
} }
} }
private static getTimestampAndAuthor(entry: HistoryEntry): string {
let content = intlFormatDistance(entry.timestamp, new Date());
if ("author" in entry && entry.author !== undefined) {
content += ` by ${entry.author}`;
}
return content;
}
public getViewType(): string { public getViewType(): string {
return HistoryView.TYPE; return HistoryView.TYPE;
} }
@ -152,11 +167,14 @@ export class HistoryView extends ItemView {
cls: ["history-card", entry.status.toLocaleLowerCase()] cls: ["history-card", entry.status.toLocaleLowerCase()]
}, },
(card) => { (card) => {
if (this.app.vault.getFileByPath(entry.relativePath) !== null) { if (
this.app.vault.getFileByPath(entry.details.relativePath) !==
null
) {
card.addEventListener("click", () => { card.addEventListener("click", () => {
void this.app.workspace.openLinkText( void this.app.workspace.openLinkText(
entry.relativePath, entry.details.relativePath,
entry.relativePath, entry.details.relativePath,
false false
); );
}); });
@ -180,17 +198,19 @@ export class HistoryView extends ItemView {
); );
header.createSpan({ header.createSpan({
text: intlFormatDistance( text: HistoryView.getTimestampAndAuthor(entry),
entry.timestamp,
new Date()
),
cls: "history-card-timestamp" cls: "history-card-timestamp"
}); });
} }
); );
const body =
entry.details.type === SyncType.MOVE
? `${entry.message}. Moved from '${entry.details.movedFrom}' to '${entry.details.relativePath}'`
: `${entry.message}.`;
card.createEl("p", { card.createEl("p", {
text: `${entry.message}.`, text: body,
cls: "history-card-message" cls: "history-card-message"
}); });
} }