Skip to content

Commit 1b7cdbf

Browse files
committed
content injection only on reload
Signed-off-by: Vedansh Saini <[email protected]>
1 parent 528787b commit 1b7cdbf

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/scripts/main.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,19 @@ document.getElementById('refreshCache').addEventListener('click', async (e) => {
8686

8787
try {
8888
const tabs = await chrome.tabs.query({active: true, currentWindow: true});
89-
const response = await chrome.tabs.sendMessage(tabs[0].id, {
89+
await chrome.tabs.sendMessage(tabs[0].id, {
9090
action: 'forceRefresh',
91-
timestamp: Date.now() // Pass timestamp to ensure cache invalidation
91+
timestamp: Date.now()
9292
});
9393

94-
if (response.success) {
95-
M.toast({html: 'Data refreshed successfully!', classes: 'green'});
96-
} else {
97-
throw new Error(response.error || 'Refresh failed');
98-
}
94+
// Reload the active tab to re-inject content
95+
chrome.tabs.reload(tabs[0].id);
96+
97+
M.toast({html: 'Data refreshed successfully!', classes: 'green'});
9998
} catch (err) {
10099
console.error('Refresh failed:', err);
101100
M.toast({html: 'Failed to refresh data', classes: 'red'});
102101
} finally {
103-
// Reset button state after a slight delay
104102
setTimeout(() => {
105103
button.classList.remove('loading');
106104
button.disabled = false;

src/scripts/scrumHelper.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ console.log("Script loaded", new Date().toISOString());
44
let refreshButton_Placed = false;
55
//# sourceURL=scrumHelper.js
66
let enableToggle = true;
7+
let hasInjectedContent = false;
78
function allIncluded() {
89
/* global $*/
910
let scrumBody = null;
@@ -142,7 +143,7 @@ function allIncluded() {
142143
return WeekDisplayPadded;
143144
}
144145

145-
const DEBUG = false;
146+
const DEBUG = true;
146147
function log( ...args) {
147148
if(DEBUG) {
148149
console.log(`[SCRUM-HELPER]:`, ...args);
@@ -347,6 +348,7 @@ function allIncluded() {
347348

348349
async function forceGithubDataRefresh() {
349350
log('Force refreshing GitHub data');
351+
hasInjectedContent = false; // Reset injection flag
350352
// clear cache
351353
githubCache = {
352354
data: null,
@@ -402,7 +404,7 @@ function allIncluded() {
402404

403405
//load initial text in scrum body
404406
function writeScrumBody() {
405-
if (!enableToggle) return;
407+
if (!enableToggle || hasInjectedContent) return;
406408

407409
setTimeout(() => {
408410
// Generate content first
@@ -445,12 +447,13 @@ function allIncluded() {
445447
}
446448

447449
window.emailClientAdapter.injectContent(elements.body, content, elements.eventTypes.contentChange);
450+
hasInjectedContent = true; // Mark as injected
448451
});
449452
}
450453

451454
//load initial scrum subject
452455
function scrumSubjectLoaded() {
453-
if (!enableToggle) return;
456+
if (!enableToggle || hasInjectedContent) return;
454457
setTimeout(() => {
455458
let name = githubUserData.name || githubUsername;
456459
let project = projectName || '<project name>';
@@ -696,15 +699,9 @@ function allIncluded() {
696699

697700
//check for github safe writing
698701
let intervalWriteGithub = setInterval(() => {
699-
if (scrumBody && githubUsername && githubIssuesData) {
702+
if (scrumBody && githubUsername && githubIssuesData && githubPrsReviewData ) {
700703
clearInterval(intervalWriteGithub);
701704
writeGithubIssuesPrs();
702-
}
703-
}, 500);
704-
//check for github prs reviews safe writing
705-
let intervalWriteGithubReviews = setInterval(() => {
706-
if (scrumBody && githubUsername && githubPrsReviewData) {
707-
clearInterval(intervalWriteGithubReviews);
708705
writeGithubPrsReviews();
709706
}
710707
}, 500);
@@ -728,6 +725,7 @@ function allIncluded() {
728725
}, 1000);
729726
}
730727
function handleRefresh() {
728+
hasInjectedContent = false; // Reset the flag before refresh
731729
allIncluded();
732730
}
733731
}

0 commit comments

Comments
 (0)