From dfde062ebd18445491ec55c2310bec8e220dfa29 Mon Sep 17 00:00:00 2001 From: Eric Neuber Date: Fri, 26 Jun 2026 10:23:24 +0200 Subject: [PATCH] Startzeitpunkt auf letzten Endzeitpunkt setzen --- src/ui.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/ui.ts b/src/ui.ts index d2114ca..64b47e5 100644 --- a/src/ui.ts +++ b/src/ui.ts @@ -158,6 +158,8 @@ export class TimetrackerUi {
+ +
` : ""} @@ -277,6 +279,16 @@ export class TimetrackerUi { return; } + if (target.id === "tt-active-start-now") { + this.resetActiveStartToNow(); + return; + } + + if (target.id === "tt-active-start-last-end") { + this.setActiveStartToLastEnd(); + return; + } + if (target.id === "tt-edit-save") { this.saveEditDraft(); return; @@ -452,6 +464,45 @@ export class TimetrackerUi { } } + private resetActiveStartToNow(): void { + try { + this.service.updateActiveStart(Date.now()); + this.activeStartDraft = null; + this.isEditingActiveStart = false; + this.render(); + logseq.App.showMsg("Active start reset to now.", "success"); + } catch (error) { + logseq.App.showMsg((error as Error).message, "error"); + } + } + + private setActiveStartToLastEnd(): void { + const entries = this.service.getState().entries; + if (!entries.length) { + logseq.App.showMsg("No entries available.", "warning"); + return; + } + + const latestEndedAtEpochMs = entries.reduce((latest, entry) => { + return Math.max(latest, entry.endedAtEpochMs); + }, Number.NEGATIVE_INFINITY); + + if (!Number.isFinite(latestEndedAtEpochMs)) { + logseq.App.showMsg("No valid end timestamp found.", "error"); + return; + } + + try { + this.service.updateActiveStart(latestEndedAtEpochMs); + this.activeStartDraft = null; + this.isEditingActiveStart = false; + this.render(); + logseq.App.showMsg("Active start set to last end time.", "success"); + } catch (error) { + logseq.App.showMsg((error as Error).message, "error"); + } + } + private escapeHtml(value: string): string { return value .replace(/&/g, "&")