Skip to content

Commit b21709e

Browse files
committed
refresh cache issue fix
Signed-off-by: Vedansh Saini <[email protected]>
1 parent 7f288fd commit b21709e

File tree

4 files changed

+70
-69
lines changed

4 files changed

+70
-69
lines changed

src/index.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,20 @@ body,input,div,h3,h4,p,label,hr, #scrumReport{
165165
.dark-mode .disabled-content {
166166
opacity: 0.4 !important;
167167
}
168+
.cache-info {
169+
font-size: 11px;
170+
color: #6b7280;
171+
text-align: center;
172+
margin-top: 8px;
173+
line-height: 1.3;
174+
}
175+
176+
.cache-info i {
177+
margin-right: 4px;
178+
font-size: 10px;
179+
}
180+
181+
/* Dark mode for cache info */
182+
.dark-mode .cache-info {
183+
color: #9ca3af;
184+
}

src/popup.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ <h4>Your Github Username</h4>
7373
<input type="date" id="endingDate" class="border-2 border-gray-200 bg-gray-200 rounded-xl p-1">
7474
</div>
7575
</div>
76-
<button id="refreshCache" class="w-full mt-3 bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded flex items-center justify-center gap-2 transition-colors duration-200">
77-
<i class="fa fa-refresh"></i>
78-
<span>Refresh Data (bypass cache)</span>
79-
</button>
8076
</div>
8177

8278
<div class="col s12">
@@ -104,9 +100,17 @@ <h6 class="text-base font-semibold">Scrum Report</h6>
104100
<button id="copyReport" class="flex items-center gap-2 bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded">
105101
<i class="fa fa-copy"></i> Copy Report
106102
</button>
107-
</div>
108-
109-
103+
</div>
104+
<div class="">
105+
<button id="refreshCache" class="w-full mt-3 bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded flex items-center justify-center gap-2 transition-colors duration-200">
106+
<i class="fa fa-refresh"></i>
107+
<span>Refresh Data (bypass cache)</span>
108+
</button>
109+
<p class="cache-info">
110+
<i class="fa fa-info-circle"></i>
111+
Data is cached for 10 minutes. Use this button to fetch fresh data immediately.
112+
</p>
113+
</div>
110114
<div class="border-gray-100 border-2 bg-white rounded-3xl px-4 py-2 mx-2 my-2">
111115
<div>
112116
<h4 class="font-semibold text-xl">Note:</h4>

src/scripts/popup.js

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -191,36 +191,6 @@ document.addEventListener('DOMContentLoaded', function() {
191191
}
192192
});
193193

194-
// refresh cache button
195-
document.getElementById('refreshCache').addEventListener('click', async function () {
196-
const button = this;
197-
const originalText = button.innerHTML;
198-
199-
button.classList.add('loading');
200-
button.innerHTML = '<i class="fa fa-refresh fa-spin"></i><span>Refreshing...</span>';
201-
button.disabled = true;
202-
203-
try{
204-
await chrome.runtime.sendMessage({action: 'forceRefresh'});
205-
button.innerHTML = '<i class="fa fa-check"></i><span>Refreshed!</span>';
206-
button.classList.remove('loading');
207-
208-
setTimeout(() => {
209-
button.innerHTML = originalText;
210-
button.disabled = false;
211-
}, 2000);
212-
} catch (error) {
213-
console.error('Refresh failed', error);
214-
button.innerHTML = '<i class="fa fa-exclamation-triangle"></i><span>Failed to refresh</span>';
215-
button.classList.remove('loading');
216-
217-
setTimeout(() =>{
218-
button.innerHTML = originalText;
219-
button.disabled = false;
220-
}, 2000);
221-
}
222-
})
223-
224194
// Custom date container click handler
225195
document.getElementById('customDateContainer').addEventListener('click', () => {
226196
document.querySelectorAll('input[name="timeframe"]').forEach(radio => {
@@ -310,6 +280,47 @@ document.querySelectorAll('input[name="timeframe"]').forEach(radio => {
310280
});
311281
});
312282

283+
// refresh cache button
284+
document.getElementById('refreshCache').addEventListener('click', async function () {
285+
const button = this;
286+
const originalText = button.innerHTML;
287+
288+
button.classList.add('loading');
289+
button.innerHTML = '<i class="fa fa-refresh fa-spin"></i><span>Refreshing...</span>';
290+
button.disabled = true;
291+
292+
try {
293+
// Clear local cache
294+
await new Promise(resolve => {
295+
chrome.storage.local.remove('githubCache', resolve);
296+
});
297+
298+
// Clear the scrum report
299+
const scrumReport = document.getElementById('scrumReport');
300+
if (scrumReport) {
301+
scrumReport.innerHTML = '<p style="text-align: center; color: #666; padding: 20px;">Cache cleared successfully. Click "Generate Report" to fetch fresh data.</p>';
302+
}
303+
304+
button.innerHTML = '<i class="fa fa-check"></i><span>Cache Cleared!</span>';
305+
button.classList.remove('loading');
306+
307+
setTimeout(() => {
308+
button.innerHTML = originalText;
309+
button.disabled = false;
310+
}, 2000);
311+
312+
} catch (error) {
313+
console.error('Cache clear failed:', error);
314+
button.innerHTML = '<i class="fa fa-exclamation-triangle"></i><span>Failed to clear cache</span>';
315+
button.classList.remove('loading');
316+
317+
setTimeout(() => {
318+
button.innerHTML = originalText;
319+
button.disabled = false;
320+
}, 3000);
321+
}
322+
});
323+
313324
function toggleRadio(radio) {
314325
const startDateInput = document.getElementById('startingDate');
315326
const endDateInput = document.getElementById('endingDate');

src/scripts/scrumHelper.js

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -380,38 +380,7 @@ function allIncluded(outputTarget = 'email') {
380380
}
381381
verifyCacheStatus();
382382

383-
async function forceGithubDataRefresh() {
384-
log('Force refreshing GitHub data');
385-
hasInjectedContent = false;
386-
// clear cache
387-
githubCache = {
388-
data: null,
389-
cacheKey: null,
390-
timestamp: 0,
391-
ttl: 10*60*1000,
392-
fetching: false,
393-
queue: [],
394-
errors: {},
395-
errorTTL: 60*1000,
396-
subject: null
397-
};
398-
await new Promise(resolve => {
399-
chrome.storage.local.remove('githubCache', resolve);
400-
});
401-
402-
log('Cache cleared, fetching fresh data');
403-
try {
404-
await fetchGithubData();
405-
await saveToStorage();
406-
return { success: true, timestamp: Date.now() };
407-
} catch (err) {
408-
logError('Force refresh failed:', err);
409-
throw err;
410-
}
411-
}
412-
if(typeof window !== 'undefined') {
413-
window.forceGithubDataRefresh = forceGithubDataRefresh;
414-
}
383+
415384

416385
function processGithubData(data) {
417386
log('Processing Github data');

0 commit comments

Comments
 (0)