@@ -214,9 +214,16 @@ document.addEventListener('DOMContentLoaded', function () {
214
214
const copyBtn = document . getElementById ( 'copyReport' ) ;
215
215
216
216
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
+ } ) ;
220
227
} ) ;
221
228
222
229
copyBtn . addEventListener ( 'click' , function ( ) {
@@ -276,11 +283,11 @@ document.addEventListener('DOMContentLoaded', function () {
276
283
console . log ( 'Restoring state:' , items ) ;
277
284
278
285
279
- if ( items . startingDate && items . endingDate && ! items . lastWeekContribution && ! items . yesterdayContribution ) {
286
+ if ( items . startingDate && items . endingDate && ! items . lastWeekContribution && ! items . yesterdayContribution ) {
280
287
const startDateInput = document . getElementById ( 'startingDate' ) ;
281
288
const endDateInput = document . getElementById ( 'endingDate' ) ;
282
289
283
- if ( startDateInput && endDateInput ) {
290
+ if ( startDateInput && endDateInput ) {
284
291
285
292
startDateInput . value = items . startingDate ;
286
293
endDateInput . value = items . endingDate ;
@@ -368,103 +375,29 @@ document.addEventListener('DOMContentLoaded', function () {
368
375
orgInput . value = result . orgName || '' ;
369
376
} ) ;
370
377
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
+
371
389
// Add click event for setOrgBtn to set org
372
390
setOrgBtn . addEventListener ( 'click' , function ( ) {
373
391
let org = orgInput . value . trim ( ) . toLowerCase ( ) ;
374
392
if ( ! org ) {
375
393
org = 'fossasia' ;
376
394
}
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 ) {
468
401
setOrgBtn . disabled = false ;
469
402
setOrgBtn . innerHTML = originalText ;
470
403
const oldToast = document . getElementById ( 'invalid-org-toast' ) ;
@@ -482,13 +415,70 @@ document.addEventListener('DOMContentLoaded', function () {
482
415
toastDiv . style . left = '50%' ;
483
416
toastDiv . style . transform = 'translateX(-50%)' ;
484
417
toastDiv . style . zIndex = '9999' ;
485
- toastDiv . innerText = 'Error validating organization .' ;
418
+ toastDiv . innerText = 'Organization not found on GitHub .' ;
486
419
document . body . appendChild ( toastDiv ) ;
487
420
setTimeout ( ( ) => {
488
421
if ( toastDiv . parentNode ) toastDiv . parentNode . removeChild ( toastDiv ) ;
489
422
} , 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 ) ;
490
456
} ) ;
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
+ } ) ;
492
482
} ) ;
493
483
494
484
let cacheInput = document . getElementById ( 'cacheInput' ) ;
0 commit comments