From 9d1f186e5e461d9e13bc7606a5573a437d1d849c Mon Sep 17 00:00:00 2001 From: Maxime Cannoodt Date: Tue, 22 Feb 2022 19:42:48 +0100 Subject: [PATCH 1/3] fix: :bug: Fix timers having "Unknown project" on opening Obsidian --- CHANGELOG.md | 6 ++++++ lib/model/Project.ts | 2 +- lib/toggl/TogglManager.ts | 19 +++++++++++++++++-- lib/toggl/toggl-client | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) create mode 160000 lib/toggl/toggl-client diff --git a/CHANGELOG.md b/CHANGELOG.md index 83a57a7..ff143ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [0.7.2] + +### 🐛 Fixes + +- Fix timers having "Unknown project" on opening Obsidian (issue #32) + ## [0.7.1] ### ✨ Features diff --git a/lib/model/Project.ts b/lib/model/Project.ts index d29fd88..98fb0f8 100644 --- a/lib/model/Project.ts +++ b/lib/model/Project.ts @@ -7,7 +7,7 @@ export interface Project { /** * Project ID in Toggl API */ - id: string; + id: number; /** * Client ID for the project diff --git a/lib/toggl/TogglManager.ts b/lib/toggl/TogglManager.ts index c4c8c6b..f8408e5 100644 --- a/lib/toggl/TogglManager.ts +++ b/lib/toggl/TogglManager.ts @@ -92,6 +92,21 @@ export default class TogglManager { private async _preloadWorkspaceData() { this._apiManager.getProjects().then((response: Project[]) => { this._projects = response; + + // Update the current timer if it was fetched before the preload finished. + currentTimer.update((entry) => { + if (entry && entry.pid !== undefined) { + const project = response.find((p) => p.id === entry.pid); + return { + ...entry, + project: project.name, + project_hex_color: project.hex_color + }; + } + return entry; + }); + + // if there is already a timer running, add the project name. }); this._apiManager.getTags().then((response: Tag[]) => { this._tags = response; @@ -142,7 +157,7 @@ export default class TogglManager { if (new_timer == null) { const project = await this._plugin.input.selectProject(); new_timer = await this._plugin.input.enterTimerDetails(); - new_timer.pid = project != null ? parseInt(project.id) : null; + new_timer.pid = project != null ? project.id : null; } this._apiManager.startTimer(new_timer).then((t: TimeEntry) => { @@ -415,7 +430,7 @@ export default class TogglManager { // NOTE: relies on cached projects for project names private responseToTimeEntry(response: any): TimeEntry { - let project = this.cachedProjects.find((p) => p.id == response.pid); + const project = this.cachedProjects.find((p) => p.id == response.pid); return { description: response.description, pid: response.pid, diff --git a/lib/toggl/toggl-client b/lib/toggl/toggl-client new file mode 160000 index 0000000..0f5a960 --- /dev/null +++ b/lib/toggl/toggl-client @@ -0,0 +1 @@ +Subproject commit 0f5a9604aba06e7bb4428248f95b636ef796dae6 From 70a0bd37868c2f518f6f06b3b91b8d5d5a0dca7a Mon Sep 17 00:00:00 2001 From: Maxime Cannoodt Date: Tue, 22 Feb 2022 19:52:25 +0100 Subject: [PATCH 2/3] fix: :lipstick: Make start/stop button more visible on low-contrast themes (Minimal theme) (issue #67) --- CHANGELOG.md | 1 + .../current_timer/CurrentTimerStartButton.svelte | 7 +++---- .../components/current_timer/CurrentTimerStopButton.svelte | 7 +++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff143ed..c7d0e47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### 🐛 Fixes - Fix timers having "Unknown project" on opening Obsidian (issue #32) +- Fixed the start/stop button accent color to be more accessible on Minimal Theme (issue #67) ## [0.7.1] diff --git a/lib/ui/components/current_timer/CurrentTimerStartButton.svelte b/lib/ui/components/current_timer/CurrentTimerStartButton.svelte index 0b144d2..a0b84a9 100644 --- a/lib/ui/components/current_timer/CurrentTimerStartButton.svelte +++ b/lib/ui/components/current_timer/CurrentTimerStartButton.svelte @@ -1,6 +1,5 @@