Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,14 @@ <h4>Organization Name</h4>
</span>
</span>
</div>
<input id="orgInput" type="text"
class="w-full border-2 border-gray-200 bg-gray-200 rounded-xl text-gray-800 p-2 my-2"
placeholder="Enter organization name (default: fossasia)">
<div class="flex items-center mt-4 gap-2">
<input id="orgInput" type="text"
class="w-full border-2 border-gray-200 bg-gray-200 rounded-xl text-gray-800 p-2 my-2"
placeholder="Enter organization name(Default: fossasia)">
<button id="setOrgBtn" type="button"
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"
style="min-width:60px;">Set</button>
</div>
</div>
<div class="">
<div class="flex items-center justify-between">
Expand Down
24 changes: 12 additions & 12 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,19 @@ function handleLastWeekContributionChange() {
let value = lastWeekContributionElement.checked;
let labelElement = document.querySelector("label[for='lastWeekContribution']");
if (value) {
startingDateElement.readOnly = true;
endingDateElement.readOnly = true;
endingDateElement.value = getToday();
startingDateElement.value = getLastWeek();
handleEndingDateChange();
handleStartingDateChange();
labelElement.classList.add("selectedLabel");
labelElement.classList.remove("unselectedLabel");
startingDateElement.readOnly = true;
endingDateElement.readOnly = true;
endingDateElement.value = getToday();
startingDateElement.value = getLastWeek();
handleEndingDateChange();
handleStartingDateChange();
labelElement.classList.add("selectedLabel");
labelElement.classList.remove("unselectedLabel");
} else {
startingDateElement.readOnly = false;
endingDateElement.readOnly = false;
labelElement.classList.add("unselectedLabel");
labelElement.classList.remove("selectedLabel");
startingDateElement.readOnly = false;
endingDateElement.readOnly = false;
labelElement.classList.add("unselectedLabel");
labelElement.classList.remove("selectedLabel");
}

chrome.storage.local.set({ lastWeekContribution: value });
Expand Down
149 changes: 93 additions & 56 deletions src/scripts/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,16 @@ document.addEventListener('DOMContentLoaded', function () {
const copyBtn = document.getElementById('copyReport');

generateBtn.addEventListener('click', function () {
this.innerHTML = '<i class="fa fa-spinner fa-spin"></i> Generating...';
this.disabled = true;
window.generateScrumReport();
// Check org input value before generating report
let org = orgInput.value.trim().toLowerCase();
if (!org) {
org = 'fossasia';
}
chrome.storage.local.set({ orgName: org }, () => {
generateBtn.innerHTML = '<i class="fa fa-spinner fa-spin"></i> Generating...';
generateBtn.disabled = true;
window.generateScrumReport();
});
});

copyBtn.addEventListener('click', function () {
Expand Down Expand Up @@ -276,11 +283,13 @@ document.addEventListener('DOMContentLoaded', function () {
], (items) => {
console.log('Restoring state:', items);

if(items.startingDate && items.endingDate && !items.lastWeekContribution && !items.yesterdayContribution) {

if (items.startingDate && items.endingDate && !items.lastWeekContribution && !items.yesterdayContribution) {
const startDateInput = document.getElementById('startingDate');
const endDateInput = document.getElementById('endingDate');

if(startDateInput && endDateInput) {
if (startDateInput && endDateInput) {

startDateInput.value = items.startingDate;
endDateInput.value = items.endingDate;
startDateInput.readOnly = false;
Expand Down Expand Up @@ -315,7 +324,7 @@ document.addEventListener('DOMContentLoaded', function () {
endDateInput.value = getToday();
}
startDateInput.readOnly = endDateInput.readOnly = true;

chrome.storage.local.set({
startingDate: startDateInput.value,
endingDate: endDateInput.value,
Expand Down Expand Up @@ -367,28 +376,31 @@ document.addEventListener('DOMContentLoaded', function () {
orgInput.value = result.orgName || '';
});

// Debounce function
function debounce(func, wait) {
let timeout;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), wait);
};
}
// Auto-update orgName in storage on input change
orgInput.addEventListener('input', function () {
let org = orgInput.value.trim().toLowerCase();
if (!org) {
org = 'fossasia';
}
chrome.storage.local.set({ orgName: org }, function () {
chrome.storage.local.remove('githubCache'); // Clear cache on org change
});
});

let lastInvalidOrg = '';
// Validate and set org as user types
const handleOrgInput = debounce(function () {
// Add click event for setOrgBtn to set org
setOrgBtn.addEventListener('click', function () {
let org = orgInput.value.trim().toLowerCase();
if (!org) {
org = 'fossasia';
}
console.log('[Org Check] Checking organization:', org);
setOrgBtn.disabled = true;
const originalText = setOrgBtn.innerHTML;
setOrgBtn.innerHTML = '<i class="fa fa-spinner fa-spin"></i>';
fetch(`https://api.github.com/orgs/${org}`)
.then(res => {
console.log('[Org Check] Response status for', org, ':', res.status);
if (res.status === 404) {
console.log('[Org Check] Organization not found on GitHub:', org);
setOrgBtn.disabled = false;
setOrgBtn.innerHTML = originalText;
const oldToast = document.getElementById('invalid-org-toast');
if (oldToast) oldToast.parentNode.removeChild(oldToast);
const toastDiv = document.createElement('div');
Expand All @@ -413,14 +425,40 @@ document.addEventListener('DOMContentLoaded', function () {
}
const oldToast = document.getElementById('invalid-org-toast');
if (oldToast) oldToast.parentNode.removeChild(oldToast);
console.log('[Org Check] Organisation exists on GitHub:', org);
console.log('[Org Check] Organization exists on GitHub:', org);
chrome.storage.local.set({ orgName: org }, function () {
if (window.generateScrumReport) window.generateScrumReport();
// Always clear the scrum report and show org changed message
const scrumReport = document.getElementById('scrumReport');
if (scrumReport) {
scrumReport.innerHTML = '<p style="text-align: center; color: #666; padding: 20px;">Organization changed. Click Generate button to fetch the GitHub activities.</p>';
}
// Clear the githubCache for previous org
chrome.storage.local.remove('githubCache');
setOrgBtn.disabled = false;
setOrgBtn.innerHTML = originalText;
// Always show green toast: org is set
const toastDiv = document.createElement('div');
toastDiv.id = 'invalid-org-toast';
toastDiv.className = 'toast';
toastDiv.style.background = '#10b981';
toastDiv.style.color = '#fff';
toastDiv.style.fontWeight = 'bold';
toastDiv.style.padding = '12px 24px';
toastDiv.style.borderRadius = '8px';
toastDiv.style.position = 'fixed';
toastDiv.style.top = '24px';
toastDiv.style.left = '50%';
toastDiv.style.transform = 'translateX(-50%)';
toastDiv.style.zIndex = '9999';
toastDiv.innerText = 'Organization is set.';
document.body.appendChild(toastDiv);
setTimeout(() => {
if (toastDiv.parentNode) toastDiv.parentNode.removeChild(toastDiv);
}, 2500);
});
})
.catch((err) => {
console.log('[Org Check] Error validating organisation:', org, err);
setOrgBtn.disabled = false;
setOrgBtn.innerHTML = originalText;
const oldToast = document.getElementById('invalid-org-toast');
if (oldToast) oldToast.parentNode.removeChild(oldToast);
const toastDiv = document.createElement('div');
Expand All @@ -442,9 +480,38 @@ document.addEventListener('DOMContentLoaded', function () {
if (toastDiv.parentNode) toastDiv.parentNode.removeChild(toastDiv);
}, 3000);
});
}, 3000);
});

let cacheInput = document.getElementById('cacheInput');
if (cacheInput) {
chrome.storage.local.get(['cacheInput'], function (result) {
if (result.cacheInput) {
cacheInput.value = result.cacheInput;
} else {
cacheInput.value = 10;
}
});

cacheInput.addEventListener('blur', function () {
let ttlValue = parseInt(this.value);
if (isNaN(ttlValue) || ttlValue <= 0 || this.value.trim() === '') {
ttlValue = 10;
this.value = ttlValue;
this.style.borderColor = '#ef4444';
} else if (ttlValue > 1440) {
ttlValue = 1440;
this.value = ttlValue;
this.style.borderColor = '#f59e0b';
} else {
this.style.borderColor = '#10b981';
}

chrome.storage.local.set({ cacheInput: ttlValue }, function () {
console.log('Cache TTL saved:', ttlValue, 'minutes');
});
});

orgInput.addEventListener('input', handleOrgInput);
}

});

Expand Down Expand Up @@ -586,33 +653,3 @@ function toggleRadio(radio) {
});
}

let cacheInput = document.getElementById('cacheInput');
if (cacheInput) {
chrome.storage.local.get(['cacheInput'], function (result) {
if (result.cacheInput) {
cacheInput.value = result.cacheInput;
} else {
cacheInput.value = 10;
}
});

cacheInput.addEventListener('blur', function () {
let ttlValue = parseInt(this.value);
if (isNaN(ttlValue) || ttlValue <= 0 || this.value.trim() === '') {
ttlValue = 10;
this.value = ttlValue;
this.style.borderColor = '#ef4444';
} else if (ttlValue > 1440) {
ttlValue = 1440;
this.value = ttlValue;
this.style.borderColor = '#f59e0b';
} else {
this.style.borderColor = '#10b981';
}

chrome.storage.local.set({ cacheInput: ttlValue }, function () {
console.log('Cache TTL saved:', ttlValue, 'minutes');
});
});

}
Loading