Improve history view UX
This commit is contained in:
parent
b9cf16be18
commit
8ab64b170a
2 changed files with 110 additions and 43 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
padding: var(--size-2-1) var(--size-4-1);
|
padding: var(--size-2-1) var(--size-4-1);
|
||||||
border-radius: var(--radius-s);
|
border-radius: var(--radius-s);
|
||||||
background-color: var(--color-base-30);
|
background-color: var(--color-base-30);
|
||||||
font-family: var(--font-monospace-default);
|
font-family: var(--font-monospace);
|
||||||
font-weight: var(--bold-weight);
|
font-weight: var(--bold-weight);
|
||||||
font-size: var(--font-ui-small);
|
font-size: var(--font-ui-small);
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.log-message {
|
.log-message {
|
||||||
font: var(--font-monospace-theme);
|
font: var(--font-monospace);
|
||||||
|
|
||||||
&.DEBUG {
|
&.DEBUG {
|
||||||
color: var(--color-base-50);
|
color: var(--color-base-50);
|
||||||
|
|
@ -105,10 +105,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.history-card {
|
.history-card {
|
||||||
padding: var(--size-4-4) var(--size-4-6);
|
padding: var(--size-4-4);
|
||||||
margin: var(--size-4-2);
|
margin: var(--size-4-2);
|
||||||
background-color: var(--color-base-00);
|
background-color: var(--color-base-00);
|
||||||
border-radius: var(--radius-l);
|
border-radius: var(--radius-l);
|
||||||
|
container-type: inline-size;
|
||||||
|
|
||||||
|
&.clickable {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
&.success {
|
&.success {
|
||||||
background-color: rgba(var(--color-green-rgb), 0.2);
|
background-color: rgba(var(--color-green-rgb), 0.2);
|
||||||
|
|
@ -118,29 +123,36 @@
|
||||||
background-color: rgba(var(--color-red-rgb), 0.2);
|
background-color: rgba(var(--color-red-rgb), 0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
* {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.history-card-header {
|
.history-card-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-bottom: var(--size-4-4);
|
margin-bottom: var(--size-4-2);
|
||||||
|
gap: var(--size-4-2);
|
||||||
|
|
||||||
|
@container (max-width: 300px) {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
.history-card-title {
|
.history-card-title {
|
||||||
font: var(--font-monospace-theme);
|
font: var(--font-monospace);
|
||||||
|
display: flex;
|
||||||
|
gap: var(--size-4-2);
|
||||||
|
word-break: break-all;
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.history-card-timestamp {
|
.history-card-timestamp {
|
||||||
font-size: var(--font-ui-small);
|
font-size: var(--font-ui-small);
|
||||||
color: var(--color-base-70);
|
font-style: italic;
|
||||||
|
color: var(--italic-color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.history-card-message {
|
.history-card-message {
|
||||||
font-size: var(--font-ui-medium);
|
font-size: var(--font-ui-medium);
|
||||||
color: var(--color-base-70);
|
color: var(--color-base-70);
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import type { WorkspaceLeaf } from "obsidian";
|
import type { IconName, WorkspaceLeaf } from "obsidian";
|
||||||
import { ItemView } from "obsidian";
|
import { ItemView, setIcon } from "obsidian";
|
||||||
import type { SyncHistory} from "src/tracing/sync-history";
|
import type { HistoryEntry, SyncHistory } from "src/tracing/sync-history";
|
||||||
import { SyncType } from "src/tracing/sync-history";
|
import { SyncType } from "src/tracing/sync-history";
|
||||||
import { SyncSource, SyncStatus } from "src/tracing/sync-history";
|
import { SyncSource, SyncStatus } from "src/tracing/sync-history";
|
||||||
import { intlFormatDistance } from "date-fns";
|
import { intlFormatDistance } from "date-fns";
|
||||||
|
|
@ -25,32 +25,51 @@ export class HistoryView extends ItemView {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static formatSyncType(type: SyncType | undefined): string {
|
private static getSyncTypeIcon(type: SyncType | undefined): IconName {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SyncType.CREATE:
|
case SyncType.CREATE:
|
||||||
return "👶 ";
|
return "file-plus";
|
||||||
case SyncType.DELETE:
|
case SyncType.DELETE:
|
||||||
return "🗑️ ";
|
return "trash-2";
|
||||||
case SyncType.UPDATE:
|
case SyncType.UPDATE:
|
||||||
return "✍️ ";
|
return "file-pen-line";
|
||||||
case undefined:
|
case undefined:
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static formatSource(source: SyncSource | undefined): string {
|
private static getSyncSourceIcon(source: SyncSource | undefined): IconName {
|
||||||
switch (source) {
|
switch (source) {
|
||||||
case SyncSource.PUSH:
|
case SyncSource.PUSH:
|
||||||
return " ⤴️";
|
return "upload";
|
||||||
case SyncSource.PULL:
|
case SyncSource.PULL:
|
||||||
return " ⤵️";
|
return "download";
|
||||||
case undefined:
|
case undefined:
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static renderSyncItemTitle(
|
||||||
|
element: HTMLElement,
|
||||||
|
entry: HistoryEntry
|
||||||
|
): void {
|
||||||
|
const syncTypeIcon = HistoryView.getSyncTypeIcon(entry.type);
|
||||||
|
if (syncTypeIcon) {
|
||||||
|
setIcon(element.createDiv(), syncTypeIcon);
|
||||||
|
}
|
||||||
|
|
||||||
|
element.createEl("span", {
|
||||||
|
text: entry.relativePath,
|
||||||
|
});
|
||||||
|
|
||||||
|
const syncSourceIcon = HistoryView.getSyncSourceIcon(entry.source);
|
||||||
|
if (syncSourceIcon) {
|
||||||
|
setIcon(element.createDiv(), syncSourceIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public getViewType(): string {
|
public getViewType(): string {
|
||||||
return HistoryView.TYPE;
|
return HistoryView.TYPE;
|
||||||
}
|
}
|
||||||
|
|
@ -76,34 +95,70 @@ export class HistoryView extends ItemView {
|
||||||
container.empty();
|
container.empty();
|
||||||
container.createEl("h4", { text: "VaultLink History" });
|
container.createEl("h4", { text: "VaultLink History" });
|
||||||
|
|
||||||
this.history
|
const entries = this.history
|
||||||
.getEntries()
|
.getEntries()
|
||||||
.reverse()
|
.reverse()
|
||||||
.filter(
|
.filter(
|
||||||
(entry) =>
|
(entry) =>
|
||||||
entry.status !== SyncStatus.NO_OP ||
|
entry.status !== SyncStatus.NO_OP ||
|
||||||
this.database.getSettings().displayNoopSyncEvents
|
this.database.getSettings().displayNoopSyncEvents
|
||||||
)
|
);
|
||||||
.forEach((entry) => {
|
|
||||||
const card = container.createDiv({
|
entries.forEach((entry) => {
|
||||||
|
container.createDiv(
|
||||||
|
{
|
||||||
cls: ["history-card", entry.status.toLocaleLowerCase()],
|
cls: ["history-card", entry.status.toLocaleLowerCase()],
|
||||||
|
},
|
||||||
|
(card) => {
|
||||||
|
if (
|
||||||
|
this.app.vault.getFileByPath(entry.relativePath) !==
|
||||||
|
null
|
||||||
|
) {
|
||||||
|
card.addEventListener("click", () => {
|
||||||
|
void this.app.workspace.openLinkText(
|
||||||
|
entry.relativePath,
|
||||||
|
entry.relativePath,
|
||||||
|
false
|
||||||
|
);
|
||||||
});
|
});
|
||||||
const header = card.createDiv({ cls: "history-card-header" });
|
|
||||||
header.createEl("h5", {
|
card.addClass("clickable");
|
||||||
text:
|
}
|
||||||
HistoryView.formatSyncType(entry.type) +
|
|
||||||
entry.relativePath +
|
card.createDiv(
|
||||||
HistoryView.formatSource(entry.source),
|
{
|
||||||
|
cls: "history-card-header",
|
||||||
|
},
|
||||||
|
(header) => {
|
||||||
|
header.createEl(
|
||||||
|
"h5",
|
||||||
|
{
|
||||||
cls: "history-card-title",
|
cls: "history-card-title",
|
||||||
});
|
},
|
||||||
|
(title) => {
|
||||||
|
HistoryView.renderSyncItemTitle(
|
||||||
|
title,
|
||||||
|
entry
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
header.createSpan({
|
header.createSpan({
|
||||||
text: intlFormatDistance(entry.timestamp, new Date()),
|
text: intlFormatDistance(
|
||||||
|
entry.timestamp,
|
||||||
|
new Date()
|
||||||
|
),
|
||||||
cls: "history-card-timestamp",
|
cls: "history-card-timestamp",
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
card.createEl("p", {
|
card.createEl("p", {
|
||||||
text: entry.message,
|
text: `${entry.message}.`,
|
||||||
cls: "history-card-message",
|
cls: "history-card-message",
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue