Skip to content

Commit e06b9a6

Browse files
committed
fix buttons duplicating on start/stop
1 parent 5d437a1 commit e06b9a6

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

entrypoints/utils/jira.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,15 @@ function createJiraTimeTrackingButton(
259259
export async function injectJiraTimeTrackingButton(
260260
actionsWrapper: HTMLElement,
261261
issueDescription: string,
262+
skipExistingCheck = false,
262263
): Promise<void> {
263-
// Remove existing button if present
264+
// Check if button already exists and skip if so (unless explicitly told to replace)
264265
const existingButton = document.getElementById(BUTTON_WRAPPER_ID);
266+
if (existingButton && !skipExistingCheck) {
267+
return;
268+
}
269+
270+
// Remove existing button if present
265271
if (existingButton) {
266272
existingButton.remove();
267273
}
@@ -366,7 +372,11 @@ async function handleJiraTrackingClick(
366372
// Refresh the button
367373
const actionsWrapper = findJiraActionsWrapper();
368374
if (actionsWrapper) {
369-
await injectJiraTimeTrackingButton(actionsWrapper, issueDescription);
375+
await injectJiraTimeTrackingButton(
376+
actionsWrapper,
377+
issueDescription,
378+
true,
379+
);
370380
}
371381
} catch (error) {
372382
console.error("Failed to toggle time tracking:", error);

entrypoints/utils/linear.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,15 @@ function createTimeTrackingSection(
332332
export async function injectTimeTrackingSection(
333333
container: HTMLElement,
334334
issueDescription: string,
335+
skipExistingCheck = false,
335336
): Promise<void> {
336-
// Remove existing section if present
337+
// Check if section already exists and skip if so (unless explicitly told to replace)
337338
const existingSection = document.getElementById(SECTION_ID);
339+
if (existingSection && !skipExistingCheck) {
340+
return;
341+
}
342+
343+
// Remove existing section if present
338344
if (existingSection) {
339345
existingSection.remove();
340346
}
@@ -451,7 +457,11 @@ async function handleTrackingClick(
451457
// Refresh the section by finding the properties sidebar container
452458
const propertiesSidebar = findPropertiesSidebar();
453459
if (propertiesSidebar) {
454-
await injectTimeTrackingSection(propertiesSidebar, issueDescription);
460+
await injectTimeTrackingSection(
461+
propertiesSidebar,
462+
issueDescription,
463+
true,
464+
);
455465
}
456466
} catch (error) {
457467
console.error("Failed to toggle time tracking:", error);

entrypoints/utils/plane.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,15 @@ function createPlaneTimeTrackingButton(
244244
export async function injectPlaneTimeTrackingButton(
245245
actionsWrapper: HTMLElement,
246246
issueDescription: string,
247+
skipExistingCheck = false,
247248
): Promise<void> {
248-
// Remove existing button if present
249+
// Check if button already exists and skip if so (unless explicitly told to replace)
249250
const existingButton = document.getElementById(BUTTON_ID);
251+
if (existingButton && !skipExistingCheck) {
252+
return;
253+
}
254+
255+
// Remove existing button if present
250256
if (existingButton) {
251257
existingButton.remove();
252258
}
@@ -348,7 +354,11 @@ async function handlePlaneTrackingClick(
348354
// Refresh the button
349355
const actionsWrapper = findPlaneActionsWrapper();
350356
if (actionsWrapper) {
351-
await injectPlaneTimeTrackingButton(actionsWrapper, issueDescription);
357+
await injectPlaneTimeTrackingButton(
358+
actionsWrapper,
359+
issueDescription,
360+
true,
361+
);
352362
}
353363
} catch (error) {
354364
console.error("Failed to toggle time tracking:", error);

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "solidtime-browser-extension",
33
"description": "Official Browser Extension for solidtime",
44
"private": true,
5-
"version": "0.0.7",
5+
"version": "0.0.8",
66
"type": "module",
77
"scripts": {
88
"dev": "wxt",

0 commit comments

Comments
 (0)