Skip to content

Commit f576ed8

Browse files
committed
subject is now being cached
Signed-off-by: Vedansh Saini <[email protected]>
1 parent 99c0681 commit f576ed8

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/scripts/scrumHelper.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,22 @@ function allIncluded() {
163163
queue: [],
164164
errors: {},
165165
errorTTL: 60*1000, // 1 min error cache
166+
subject: null,
166167
};
167168
const MAX_CACHE_SIZE = 50 * 1024 * 1024; //50mb max cache
168169

169-
function saveToStorage(data) {
170+
function saveToStorage(data, subject = null) {
170171
const cacheData = {
171172
data: data,
172173
cacheKey: githubCache.cacheKey,
173174
timestamp: githubCache.timestamp,
175+
subject: subject,
174176
}
175-
// log(`Saving data to storage:`, {
176-
// cacheKey: githubCache.cacheKey,
177-
// timestamp:githubCache.timestamp,
178-
// dataSize: new Blob([JSON.stringify(data)]).size,
179-
// });
177+
log(`Saving data to storage:`, {
178+
cacheKey: githubCache.cacheKey,
179+
timestamp:githubCache.timestamp,
180+
hasSubject: !!subject,
181+
});
180182

181183
return new Promise((resolve) => {
182184
chrome.storage.local.set({ githubCache: cacheData }, () => {
@@ -215,6 +217,14 @@ function allIncluded() {
215217
githubCache.data = cache.data;
216218
githubCache.cacheKey = cache.cacheKey;
217219
githubCache.timestamp = cache.timestamp;
220+
githubCache.subject = cache.subject;
221+
222+
// use cached subject element
223+
if(cache.subject && scrumSubject) {
224+
scrumSubject.value = cache.subject;
225+
scrumSubject.dispatchEvent(new Event('input', { bubbles: true }));
226+
}
227+
218228
resolve(true);
219229
})
220230
})
@@ -357,11 +367,12 @@ function allIncluded() {
357367
lastWeekArray = [];
358368
nextWeekArray = [];
359369
reviewedPrsArray = [];
360-
githubPrsReviewDataProccessed = [];
370+
githubPrsReviewDataProccessed = {};
361371

362-
// writeGithubIssuesPrs(); //These functions are making duplicate calls, lets rewrite these source functions to fetch the data from cache instead of Review and PR data as cache stores these data.
363-
// writeGithubPrsReviews();
364-
// githubUserData = githubUserData;
372+
// Update subject
373+
if(!scrumSubject?.value) {
374+
scrumSubjectLoaded();
375+
}
365376
}
366377

367378
function formatDate(dateString) {
@@ -434,9 +445,9 @@ function allIncluded() {
434445
function scrumSubjectLoaded() {
435446
if (!enableToggle) return;
436447
setTimeout(() => {
437-
//to apply this after google has autofilled
438448
let name = githubUserData.name || githubUsername;
439-
let project = getProject();
449+
// let project = getProject();
450+
let project = projectName || '<project name>';
440451
let curDate = new Date();
441452
let year = curDate.getFullYear().toString();
442453
let date = curDate.getDate();
@@ -445,8 +456,17 @@ function allIncluded() {
445456
if (month < 10) month = '0' + month;
446457
if (date < 10) date = '0' + date;
447458
let dateCode = year.toString() + month.toString() + date.toString();
448-
scrumSubject.value = '[Scrum] ' + name + ' - ' + project + ' - ' + dateCode + ' - False';
449-
scrumSubject.dispatchEvent(new Event('input', { bubbles: true }));
459+
460+
const subject = `[Scrum] ${name} - ${project} - ${dateCode} - False`;
461+
log('Generated subject:', subject);
462+
// Save subject to cache
463+
githubCache.subject = subject;
464+
saveToStorage(githubCache.data, subject);
465+
466+
if(scrumSubject) {
467+
scrumSubject.value = subject;
468+
scrumSubject.dispatchEvent(new Event('input', { bubbles: true }));
469+
}
450470
});
451471
}
452472

0 commit comments

Comments
 (0)