@@ -163,20 +163,22 @@ function allIncluded() {
163
163
queue : [ ] ,
164
164
errors : { } ,
165
165
errorTTL : 60 * 1000 , // 1 min error cache
166
+ subject : null ,
166
167
} ;
167
168
const MAX_CACHE_SIZE = 50 * 1024 * 1024 ; //50mb max cache
168
169
169
- function saveToStorage ( data ) {
170
+ function saveToStorage ( data , subject = null ) {
170
171
const cacheData = {
171
172
data : data ,
172
173
cacheKey : githubCache . cacheKey ,
173
174
timestamp : githubCache . timestamp ,
175
+ subject : subject ,
174
176
}
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
+ } ) ;
180
182
181
183
return new Promise ( ( resolve ) => {
182
184
chrome . storage . local . set ( { githubCache : cacheData } , ( ) => {
@@ -215,6 +217,14 @@ function allIncluded() {
215
217
githubCache . data = cache . data ;
216
218
githubCache . cacheKey = cache . cacheKey ;
217
219
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
+
218
228
resolve ( true ) ;
219
229
} )
220
230
} )
@@ -357,11 +367,12 @@ function allIncluded() {
357
367
lastWeekArray = [ ] ;
358
368
nextWeekArray = [ ] ;
359
369
reviewedPrsArray = [ ] ;
360
- githubPrsReviewDataProccessed = [ ] ;
370
+ githubPrsReviewDataProccessed = { } ;
361
371
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
+ }
365
376
}
366
377
367
378
function formatDate ( dateString ) {
@@ -434,9 +445,9 @@ function allIncluded() {
434
445
function scrumSubjectLoaded ( ) {
435
446
if ( ! enableToggle ) return ;
436
447
setTimeout ( ( ) => {
437
- //to apply this after google has autofilled
438
448
let name = githubUserData . name || githubUsername ;
439
- let project = getProject ( ) ;
449
+ // let project = getProject();
450
+ let project = projectName || '<project name>' ;
440
451
let curDate = new Date ( ) ;
441
452
let year = curDate . getFullYear ( ) . toString ( ) ;
442
453
let date = curDate . getDate ( ) ;
@@ -445,8 +456,17 @@ function allIncluded() {
445
456
if ( month < 10 ) month = '0' + month ;
446
457
if ( date < 10 ) date = '0' + date ;
447
458
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
+ }
450
470
} ) ;
451
471
}
452
472
0 commit comments