Skip to content

Commit d8ff406

Browse files
committed
fixed the race condition
Signed-off-by: Vedansh Saini <[email protected]>
1 parent 3284f5a commit d8ff406

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

src/scripts/popup.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,8 @@ document.addEventListener('DOMContentLoaded', function () {
370370
console.log('[Org Check] Response status for', org, ':', res.status);
371371
if (res.status === 404) {
372372
console.log('[Org Check] Organisation not found on GitHub:', org);
373-
// Remove any existing toast with the same id
374373
const oldToast = document.getElementById('invalid-org-toast');
375374
if (oldToast) oldToast.parentNode.removeChild(oldToast);
376-
// Create a new toast div
377375
const toastDiv = document.createElement('div');
378376
toastDiv.id = 'invalid-org-toast';
379377
toastDiv.className = 'toast';
@@ -392,24 +390,19 @@ document.addEventListener('DOMContentLoaded', function () {
392390
setTimeout(() => {
393391
if (toastDiv.parentNode) toastDiv.parentNode.removeChild(toastDiv);
394392
}, 3000);
395-
// Do NOT update storage or fetch data for invalid org
396393
return;
397394
}
398-
// Remove any existing toast with the same id (for valid orgs)
399395
const oldToast = document.getElementById('invalid-org-toast');
400396
if (oldToast) oldToast.parentNode.removeChild(oldToast);
401397
console.log('[Org Check] Organisation exists on GitHub:', org);
402-
// Valid org: update storage and fetch data
403398
chrome.storage.local.set({ orgName: org }, function () {
404399
if (window.generateScrumReport) window.generateScrumReport();
405400
});
406401
})
407402
.catch((err) => {
408403
console.log('[Org Check] Error validating organisation:', org, err);
409-
// Remove any existing toast with the same id
410404
const oldToast = document.getElementById('invalid-org-toast');
411405
if (oldToast) oldToast.parentNode.removeChild(oldToast);
412-
// Create a new toast div
413406
const toastDiv = document.createElement('div');
414407
toastDiv.id = 'invalid-org-toast';
415408
toastDiv.className = 'toast';
@@ -428,7 +421,6 @@ document.addEventListener('DOMContentLoaded', function () {
428421
setTimeout(() => {
429422
if (toastDiv.parentNode) toastDiv.parentNode.removeChild(toastDiv);
430423
}, 3000);
431-
// Do NOT update storage or fetch data for invalid org
432424
});
433425
}, 3000);
434426

src/scripts/scrumHelper.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ console.log('Script loaded, adapter exists:', !!window.emailClientAdapter);
22
let refreshButton_Placed = false;
33
let enableToggle = true;
44
let hasInjectedContent = false;
5+
let scrumGenerationInProgress = false;
56
let orgName = 'fossasia'; // default
67
function allIncluded(outputTarget = 'email') {
8+
if(scrumGenerationInProgress) {
9+
console.warn('[SCRUM-HELPER]: Scrum generation already in progress, aborting new call.');
10+
return;
11+
}
12+
scrumGenerationInProgress = true;
713
console.log('allIncluded called with outputTarget:', outputTarget);
814
console.log('Current window context:', window.location.href);
915
let scrumBody = null;
@@ -99,9 +105,14 @@ function allIncluded(outputTarget = 'email') {
99105
handleLastWeekContributionChange();
100106
} else if (items.yesterdayContribution) {
101107
handleYesterdayContributionChange();
102-
} else {
108+
} else if(items.startDate && items.endingDate) {
103109
startingDate = items.startingDate;
104110
endingDate = items.endingDate;
111+
} else {
112+
handleLastWeekContributionChange(); //when no date is stored, i.e on fresh unpack - default to last week.
113+
if(outputTarget === 'popup') {
114+
chrome.storage.local.set({ lastWeekContribution: true, yesterdayContribution: false});
115+
}
105116
}
106117

107118
if (githubUsername) {
@@ -417,6 +428,7 @@ function allIncluded(outputTarget = 'email') {
417428
generateBtn.disabled = false;
418429
}
419430
}
431+
scrumGenerationInProgress = false;
420432
throw err;
421433
} finally {
422434
githubCache.fetching = false;
@@ -550,8 +562,10 @@ ${userReason}`;
550562
generateBtn.innerHTML = '<i class="fa fa-refresh"></i> Generate Report';
551563
generateBtn.disabled = false;
552564
}
565+
scrumGenerationInProgress = false;
553566
} else {
554567
logError('Scrum report div not found');
568+
scrumGenerationInProgress = false;
555569
}
556570
} else {
557571
const elements = window.emailClientAdapter.getEditorElements();
@@ -561,6 +575,7 @@ ${userReason}`;
561575
}
562576
window.emailClientAdapter.injectContent(elements.body, content, elements.eventTypes.contentChange);
563577
hasInjectedContent = true;
578+
scrumGenerationInProgress = false;
564579
}
565580
}, 500);
566581
}
@@ -843,11 +858,14 @@ ${userReason}`;
843858
}
844859
}
845860

846-
allIncluded('email');
861+
// allIncluded('email');
847862

848-
$('button>span:contains(New conversation)').parent('button').click(() => {
849-
allIncluded();
850-
});
863+
if(window.location.protocol.startsWith('http')) {
864+
allIncluded('email');
865+
$('button>span:contains(New conversation)').parent('button').click(() => {
866+
allIncluded();
867+
});
868+
}
851869

852870
window.generateScrumReport = function () {
853871
allIncluded('popup');

0 commit comments

Comments
 (0)