Make noop updates hidable
This commit is contained in:
parent
55c07f3b82
commit
6d32e51c3e
2 changed files with 14 additions and 9 deletions
|
|
@ -5,6 +5,7 @@ export interface SyncSettings {
|
||||||
fetchChangesUpdateIntervalMs: number;
|
fetchChangesUpdateIntervalMs: number;
|
||||||
syncConcurrency: number;
|
syncConcurrency: number;
|
||||||
isSyncEnabled: boolean;
|
isSyncEnabled: boolean;
|
||||||
|
displayNoopSyncEvents: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_SETTINGS: SyncSettings = {
|
export const DEFAULT_SETTINGS: SyncSettings = {
|
||||||
|
|
@ -14,4 +15,5 @@ export const DEFAULT_SETTINGS: SyncSettings = {
|
||||||
fetchChangesUpdateIntervalMs: 1000,
|
fetchChangesUpdateIntervalMs: 1000,
|
||||||
syncConcurrency: 1,
|
syncConcurrency: 1,
|
||||||
isSyncEnabled: false,
|
isSyncEnabled: false,
|
||||||
|
displayNoopSyncEvents: false,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,18 @@
|
||||||
import type { WorkspaceLeaf } from "obsidian";
|
import type { WorkspaceLeaf } from "obsidian";
|
||||||
import { ItemView } from "obsidian";
|
import { ItemView } from "obsidian";
|
||||||
import type { SyncHistory } from "src/tracing/sync-history";
|
import type { SyncHistory } from "src/tracing/sync-history";
|
||||||
import { SyncSource } from "src/tracing/sync-history";
|
import { SyncSource, SyncStatus } from "src/tracing/sync-history";
|
||||||
import { intlFormatDistance } from "date-fns";
|
import { intlFormatDistance } from "date-fns";
|
||||||
|
import { Database } from "src/database/database";
|
||||||
|
|
||||||
export class HistoryView extends ItemView {
|
export class HistoryView extends ItemView {
|
||||||
public static readonly TYPE = "example-view";
|
public static readonly TYPE = "history-view";
|
||||||
public static readonly ICON = "square-stack";
|
public static readonly ICON = "square-stack";
|
||||||
private timer: NodeJS.Timer | null = null;
|
private timer: NodeJS.Timer | null = null;
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
leaf: WorkspaceLeaf,
|
leaf: WorkspaceLeaf,
|
||||||
|
private readonly database: Database,
|
||||||
private readonly history: SyncHistory
|
private readonly history: SyncHistory
|
||||||
) {
|
) {
|
||||||
super(leaf);
|
super(leaf);
|
||||||
|
|
@ -33,22 +35,18 @@ export class HistoryView extends ItemView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static formatTime(timestamp: Date): string {
|
|
||||||
return intlFormatDistance(timestamp, new Date());
|
|
||||||
}
|
|
||||||
|
|
||||||
public getViewType(): string {
|
public getViewType(): string {
|
||||||
return HistoryView.TYPE;
|
return HistoryView.TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getDisplayText(): string {
|
public getDisplayText(): string {
|
||||||
return "Example view";
|
return "VaultLink history";
|
||||||
}
|
}
|
||||||
|
|
||||||
public async onOpen(): Promise<void> {
|
public async onOpen(): Promise<void> {
|
||||||
await this.updateView();
|
await this.updateView();
|
||||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
this.timer = setInterval(async () => this.updateView(), 500);
|
this.timer = setInterval(async () => this.updateView(), 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async onClose(): Promise<void> {
|
public async onClose(): Promise<void> {
|
||||||
|
|
@ -65,6 +63,11 @@ export class HistoryView extends ItemView {
|
||||||
this.history
|
this.history
|
||||||
.getEntries()
|
.getEntries()
|
||||||
.reverse()
|
.reverse()
|
||||||
|
.filter(
|
||||||
|
(entry) =>
|
||||||
|
entry.status !== SyncStatus.NO_OP ||
|
||||||
|
this.database.getSettings().displayNoopSyncEvents
|
||||||
|
)
|
||||||
.forEach((entry) => {
|
.forEach((entry) => {
|
||||||
const card = container.createDiv({
|
const card = container.createDiv({
|
||||||
cls: ["history-card", entry.status.toLocaleLowerCase()],
|
cls: ["history-card", entry.status.toLocaleLowerCase()],
|
||||||
|
|
@ -77,7 +80,7 @@ export class HistoryView extends ItemView {
|
||||||
cls: "history-card-title",
|
cls: "history-card-title",
|
||||||
});
|
});
|
||||||
header.createSpan({
|
header.createSpan({
|
||||||
text: HistoryView.formatTime(entry.timestamp),
|
text: intlFormatDistance(entry.timestamp, new Date()),
|
||||||
cls: "history-card-timestamp",
|
cls: "history-card-timestamp",
|
||||||
});
|
});
|
||||||
card.createEl("p", {
|
card.createEl("p", {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue