Skip to content

Commit

Permalink
Settings: Add option to reset sync timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcain committed Oct 25, 2023
1 parent 0b51839 commit 5a43957
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, PluginSettingTab, Setting } from "obsidian";
import { App, PluginSettingTab, Setting, moment } from "obsidian";

import type ThingsLogbookPlugin from "./index";

Expand Down Expand Up @@ -46,6 +46,8 @@ export class ThingsLogbookSettingsTab extends PluginSettingTab {
display(): void {
this.containerEl.empty();

this.addResetLastSyncSetting();

this.containerEl.createEl("h3", {
text: "Format Settings",
});
Expand Down Expand Up @@ -167,4 +169,38 @@ export class ThingsLogbookSettingsTab extends PluginSettingTab {
});
});
}

addResetLastSyncSetting(): void {
const { latestSyncTime } = this.plugin.options;
const syncTime = latestSyncTime > 0
? moment.unix(this.plugin.options.latestSyncTime).fromNow()
: 'Never';

new Setting(this.containerEl)
.setDesc(createFragment(el => {
el.appendText('Last sync: ');
el.createSpan({ cls: 'u-pop', text: syncTime });
}))
.addButton(button => {
button.setButtonText('Sync now');
button.setClass('mod-cta');
button.onClick(async () => {
button.setDisabled(true);
await this.plugin.syncLogbook();
this.display();
});
})
.addButton(button => {
button.setButtonText('Reset sync history');
button.setClass('mod-danger');
button.onClick(async () => {
await this.plugin.writeOptions({ latestSyncTime: 0 });
this.display();
});
})
.addExtraButton(component => {
component.setIcon('lucide-info');
component.setTooltip('Reseting the sync history will cause Things Logbook to rewrite rewrite the Logbook to all existing daily notes.');
});
}
}

0 comments on commit 5a43957

Please sign in to comment.