22 ChangeDetectorRef ,
33 Component ,
44 EventEmitter ,
5+ NgZone ,
56 Output ,
67} from '@angular/core' ;
78import { FormBuilder } from '@angular/forms' ;
@@ -37,7 +38,8 @@ export class AppComponent {
3738 private formBuilder : FormBuilder ,
3839 private _appService : SrcService ,
3940 private cdRef : ChangeDetectorRef ,
40- private _snackBarService : SnackbarService
41+ private _snackBarService : SnackbarService ,
42+ private ngZone : NgZone
4143 ) {
4244 chrome . storage . local . get ( 'sessions' , async ( data2 ) => {
4345 console . debug ( 'reading local sessions' , data2 . sessions ) ;
@@ -97,14 +99,7 @@ export class AppComponent {
9799
98100 if ( ! Array . isArray ( sessions ) || ! sessions . length ) {
99101 console . debug ( 'unable to get sessions' ) ;
100- this . _snackBarService . show (
101- AppStringLiterals . LEETCODE_SESSION_ERROR ,
102- 'failure' ,
103- undefined ,
104- {
105- duration : 3000 ,
106- }
107- ) ;
102+ this . showSessionError ( ) ;
108103 } else {
109104 this . isLoading = false ;
110105 console . debug ( 'Fetched sessions: ' , sessions ) ;
@@ -116,17 +111,9 @@ export class AppComponent {
116111 } catch ( err ) {
117112 this . isLoading = false ;
118113 console . debug ( 'unable to get sessions:' , err ) ;
119- this . _snackBarService . show (
120- AppStringLiterals . LEETCODE_SESSION_ERROR ,
121- 'failure' ,
122- undefined ,
123- {
124- duration : 2000 ,
125- }
126- ) ;
114+ this . showSessionError ( ) ;
127115 }
128116 this . isLoading = false ;
129- this . cdRef . detectChanges ( ) ;
130117 }
131118
132119 /**
@@ -139,4 +126,19 @@ export class AppComponent {
139126 // refresh leetcode sessions
140127 await this . refreshLeetcodeSessions ( ) ;
141128 }
129+
130+ showSessionError ( ) {
131+ this . ngZone . run ( ( ) => {
132+ setTimeout ( ( ) => {
133+ this . _snackBarService . show (
134+ AppStringLiterals . LEETCODE_SESSION_ERROR ,
135+ 'failure' ,
136+ undefined ,
137+ {
138+ duration : 1000 ,
139+ }
140+ ) ;
141+ } , 0 ) ;
142+ } ) ;
143+ }
142144}
0 commit comments