Skip to content

Commit 5d8b03e

Browse files
committed
set default to fossasia
1 parent 83cec67 commit 5d8b03e

File tree

2 files changed

+89
-99
lines changed

2 files changed

+89
-99
lines changed

src/popup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ <h4>Organization Name</h4>
143143
<div class="flex items-center mt-4 gap-2">
144144
<input id="orgInput" type="text"
145145
class="w-full border-2 border-gray-200 bg-gray-200 rounded-xl text-gray-800 p-2 my-2"
146-
placeholder="Enter organization name">
146+
placeholder="Enter organization name(Default: fossasia)">
147147
<button id="setOrgBtn" type="button"
148148
class="px-5 py-2 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-xl text-base my-2 h-[44px] flex-shrink-0"
149149
style="min-width:60px;">Set</button>

src/scripts/popup.js

Lines changed: 88 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,16 @@ document.addEventListener('DOMContentLoaded', function () {
214214
const copyBtn = document.getElementById('copyReport');
215215

216216
generateBtn.addEventListener('click', function () {
217-
this.innerHTML = '<i class="fa fa-spinner fa-spin"></i> Generating...';
218-
this.disabled = true;
219-
window.generateScrumReport();
217+
// Check org input value before generating report
218+
let org = orgInput.value.trim().toLowerCase();
219+
if (!org) {
220+
org = 'fossasia';
221+
}
222+
chrome.storage.local.set({ orgName: org }, () => {
223+
generateBtn.innerHTML = '<i class="fa fa-spinner fa-spin"></i> Generating...';
224+
generateBtn.disabled = true;
225+
window.generateScrumReport();
226+
});
220227
});
221228

222229
copyBtn.addEventListener('click', function () {
@@ -276,11 +283,11 @@ document.addEventListener('DOMContentLoaded', function () {
276283
console.log('Restoring state:', items);
277284

278285

279-
if(items.startingDate && items.endingDate && !items.lastWeekContribution && !items.yesterdayContribution) {
286+
if (items.startingDate && items.endingDate && !items.lastWeekContribution && !items.yesterdayContribution) {
280287
const startDateInput = document.getElementById('startingDate');
281288
const endDateInput = document.getElementById('endingDate');
282289

283-
if(startDateInput && endDateInput) {
290+
if (startDateInput && endDateInput) {
284291

285292
startDateInput.value = items.startingDate;
286293
endDateInput.value = items.endingDate;
@@ -368,103 +375,29 @@ document.addEventListener('DOMContentLoaded', function () {
368375
orgInput.value = result.orgName || '';
369376
});
370377

378+
// Auto-update orgName in storage on input change
379+
orgInput.addEventListener('input', function () {
380+
let org = orgInput.value.trim().toLowerCase();
381+
if (!org) {
382+
org = 'fossasia';
383+
}
384+
chrome.storage.local.set({ orgName: org }, function () {
385+
chrome.storage.local.remove('githubCache'); // Clear cache on org change
386+
});
387+
});
388+
371389
// Add click event for setOrgBtn to set org
372390
setOrgBtn.addEventListener('click', function () {
373391
let org = orgInput.value.trim().toLowerCase();
374392
if (!org) {
375393
org = 'fossasia';
376394
}
377-
// Check if org is already set
378-
chrome.storage.local.get(['orgName'], function (result) {
379-
if (result.orgName && result.orgName.toLowerCase() === org) {
380-
// Show toast: org already set
381-
const oldToast = document.getElementById('invalid-org-toast');
382-
if (oldToast) oldToast.parentNode.removeChild(oldToast);
383-
const toastDiv = document.createElement('div');
384-
toastDiv.id = 'invalid-org-toast';
385-
toastDiv.className = 'toast';
386-
toastDiv.style.background = '#2563eb';
387-
toastDiv.style.color = '#fff';
388-
toastDiv.style.fontWeight = 'bold';
389-
toastDiv.style.padding = '12px 24px';
390-
toastDiv.style.borderRadius = '8px';
391-
toastDiv.style.position = 'fixed';
392-
toastDiv.style.top = '24px';
393-
toastDiv.style.left = '50%';
394-
toastDiv.style.transform = 'translateX(-50%)';
395-
toastDiv.style.zIndex = '9999';
396-
toastDiv.innerText = 'Organization is already set to this value.';
397-
document.body.appendChild(toastDiv);
398-
setTimeout(() => {
399-
if (toastDiv.parentNode) toastDiv.parentNode.removeChild(toastDiv);
400-
}, 2500);
401-
return;
402-
}
403-
// Show loading spinner only
404-
setOrgBtn.disabled = true;
405-
const originalText = setOrgBtn.innerHTML;
406-
setOrgBtn.innerHTML = '<i class="fa fa-spinner fa-spin"></i>';
407-
fetch(`https://api.github.com/orgs/${org}`)
408-
.then(res => {
409-
if (res.status === 404) {
410-
setOrgBtn.disabled = false;
411-
setOrgBtn.innerHTML = originalText;
412-
const oldToast = document.getElementById('invalid-org-toast');
413-
if (oldToast) oldToast.parentNode.removeChild(oldToast);
414-
const toastDiv = document.createElement('div');
415-
toastDiv.id = 'invalid-org-toast';
416-
toastDiv.className = 'toast';
417-
toastDiv.style.background = '#dc2626';
418-
toastDiv.style.color = '#fff';
419-
toastDiv.style.fontWeight = 'bold';
420-
toastDiv.style.padding = '12px 24px';
421-
toastDiv.style.borderRadius = '8px';
422-
toastDiv.style.position = 'fixed';
423-
toastDiv.style.top = '24px';
424-
toastDiv.style.left = '50%';
425-
toastDiv.style.transform = 'translateX(-50%)';
426-
toastDiv.style.zIndex = '9999';
427-
toastDiv.innerText = 'Organization not found on GitHub.';
428-
document.body.appendChild(toastDiv);
429-
setTimeout(() => {
430-
if (toastDiv.parentNode) toastDiv.parentNode.removeChild(toastDiv);
431-
}, 3000);
432-
return;
433-
}
434-
const oldToast = document.getElementById('invalid-org-toast');
435-
if (oldToast) oldToast.parentNode.removeChild(oldToast);
436-
chrome.storage.local.set({ orgName: org }, function () {
437-
// Clear the scrum report and show org changed message
438-
const scrumReport = document.getElementById('scrumReport');
439-
if (scrumReport) {
440-
scrumReport.innerHTML = '<p style="text-align: center; color: #666; padding: 20px;">Organization changed. Click Generate button to fetch the GitHub activities.</p>';
441-
}
442-
// Clear the githubCache for previous org
443-
chrome.storage.local.remove('githubCache');
444-
setOrgBtn.disabled = false;
445-
setOrgBtn.innerHTML = originalText;
446-
// Show toast: org is set
447-
const toastDiv = document.createElement('div');
448-
toastDiv.id = 'invalid-org-toast';
449-
toastDiv.className = 'toast';
450-
toastDiv.style.background = '#10b981';
451-
toastDiv.style.color = '#fff';
452-
toastDiv.style.fontWeight = 'bold';
453-
toastDiv.style.padding = '12px 24px';
454-
toastDiv.style.borderRadius = '8px';
455-
toastDiv.style.position = 'fixed';
456-
toastDiv.style.top = '24px';
457-
toastDiv.style.left = '50%';
458-
toastDiv.style.transform = 'translateX(-50%)';
459-
toastDiv.style.zIndex = '9999';
460-
toastDiv.innerText = 'Organization is set.';
461-
document.body.appendChild(toastDiv);
462-
setTimeout(() => {
463-
if (toastDiv.parentNode) toastDiv.parentNode.removeChild(toastDiv);
464-
}, 2500);
465-
});
466-
})
467-
.catch((err) => {
395+
setOrgBtn.disabled = true;
396+
const originalText = setOrgBtn.innerHTML;
397+
setOrgBtn.innerHTML = '<i class="fa fa-spinner fa-spin"></i>';
398+
fetch(`https://api.github.com/orgs/${org}`)
399+
.then(res => {
400+
if (res.status === 404) {
468401
setOrgBtn.disabled = false;
469402
setOrgBtn.innerHTML = originalText;
470403
const oldToast = document.getElementById('invalid-org-toast');
@@ -482,13 +415,70 @@ document.addEventListener('DOMContentLoaded', function () {
482415
toastDiv.style.left = '50%';
483416
toastDiv.style.transform = 'translateX(-50%)';
484417
toastDiv.style.zIndex = '9999';
485-
toastDiv.innerText = 'Error validating organization.';
418+
toastDiv.innerText = 'Organization not found on GitHub.';
486419
document.body.appendChild(toastDiv);
487420
setTimeout(() => {
488421
if (toastDiv.parentNode) toastDiv.parentNode.removeChild(toastDiv);
489422
}, 3000);
423+
return;
424+
}
425+
const oldToast = document.getElementById('invalid-org-toast');
426+
if (oldToast) oldToast.parentNode.removeChild(oldToast);
427+
chrome.storage.local.set({ orgName: org }, function () {
428+
// Always clear the scrum report and show org changed message
429+
const scrumReport = document.getElementById('scrumReport');
430+
if (scrumReport) {
431+
scrumReport.innerHTML = '<p style="text-align: center; color: #666; padding: 20px;">Organization changed. Click Generate button to fetch the GitHub activities.</p>';
432+
}
433+
// Clear the githubCache for previous org
434+
chrome.storage.local.remove('githubCache');
435+
setOrgBtn.disabled = false;
436+
setOrgBtn.innerHTML = originalText;
437+
// Always show green toast: org is set
438+
const toastDiv = document.createElement('div');
439+
toastDiv.id = 'invalid-org-toast';
440+
toastDiv.className = 'toast';
441+
toastDiv.style.background = '#10b981';
442+
toastDiv.style.color = '#fff';
443+
toastDiv.style.fontWeight = 'bold';
444+
toastDiv.style.padding = '12px 24px';
445+
toastDiv.style.borderRadius = '8px';
446+
toastDiv.style.position = 'fixed';
447+
toastDiv.style.top = '24px';
448+
toastDiv.style.left = '50%';
449+
toastDiv.style.transform = 'translateX(-50%)';
450+
toastDiv.style.zIndex = '9999';
451+
toastDiv.innerText = 'Organization is set.';
452+
document.body.appendChild(toastDiv);
453+
setTimeout(() => {
454+
if (toastDiv.parentNode) toastDiv.parentNode.removeChild(toastDiv);
455+
}, 2500);
490456
});
491-
});
457+
})
458+
.catch((err) => {
459+
setOrgBtn.disabled = false;
460+
setOrgBtn.innerHTML = originalText;
461+
const oldToast = document.getElementById('invalid-org-toast');
462+
if (oldToast) oldToast.parentNode.removeChild(oldToast);
463+
const toastDiv = document.createElement('div');
464+
toastDiv.id = 'invalid-org-toast';
465+
toastDiv.className = 'toast';
466+
toastDiv.style.background = '#dc2626';
467+
toastDiv.style.color = '#fff';
468+
toastDiv.style.fontWeight = 'bold';
469+
toastDiv.style.padding = '12px 24px';
470+
toastDiv.style.borderRadius = '8px';
471+
toastDiv.style.position = 'fixed';
472+
toastDiv.style.top = '24px';
473+
toastDiv.style.left = '50%';
474+
toastDiv.style.transform = 'translateX(-50%)';
475+
toastDiv.style.zIndex = '9999';
476+
toastDiv.innerText = 'Error validating organization.';
477+
document.body.appendChild(toastDiv);
478+
setTimeout(() => {
479+
if (toastDiv.parentNode) toastDiv.parentNode.removeChild(toastDiv);
480+
}, 3000);
481+
});
492482
});
493483

494484
let cacheInput = document.getElementById('cacheInput');

0 commit comments

Comments
 (0)