@@ -12,6 +12,7 @@ import iconPerson from '../../images/icon-person.svg?raw';
12
12
import componentCSS from './author-list.css?inline' ;
13
13
14
14
const AUTHORS_PER_PAGE = 100 ;
15
+ let authorDetailAPITimeout : number | null = null ;
15
16
16
17
/**
17
18
* Author list element.
@@ -28,7 +29,6 @@ export class RecRecAuthorList extends LitElement {
28
29
authorDetails : SemanticAuthorDetail [ ] = [ ] ;
29
30
30
31
authorStartIndex = 0 ;
31
- authorDetailAPIRetryID = 0 ;
32
32
33
33
//==========================================================================||
34
34
// Lifecycle Methods ||
@@ -81,35 +81,50 @@ export class RecRecAuthorList extends LitElement {
81
81
//==========================================================================||
82
82
// Private Helpers ||
83
83
//==========================================================================||
84
- async updateAuthorDetails ( retry ?: number , retryID ?: number ) {
84
+ async updateAuthorDetails ( retry = 3 ) {
85
85
if ( this . authors . length === 0 ) {
86
86
this . authorDetails = [ ] ;
87
87
return ;
88
88
}
89
89
90
- const retryNum = retry || 3 ;
90
+ this . updateIsSearching ( true ) ;
91
91
92
- // Quit if a newer query has succeeded
93
- if ( retryID && retryID != this . authorDetailAPIRetryID ) {
94
- return ;
95
- }
96
-
97
- // Record this query as the newest query
98
- if ( retryID === undefined ) {
99
- this . authorDetailAPIRetryID += 1 ;
92
+ if ( authorDetailAPITimeout !== null ) {
93
+ clearTimeout ( authorDetailAPITimeout ) ;
100
94
}
101
95
102
96
try {
103
97
const data = await searchAuthorDetails ( this . authors . map ( d => d . authorId ) ) ;
104
98
this . authorDetails = data ;
99
+ this . updateIsSearching ( false ) ;
105
100
} catch ( e ) {
106
- await new Promise < void > ( resolve => {
107
- setTimeout ( resolve , 1000 ) ;
108
- } ) ;
109
- await this . updateAuthorDetails ( retryNum - 1 , this . authorDetailAPIRetryID ) ;
101
+ // Try again after some delay
102
+ console . error (
103
+ `Author detail API failed with error (retry remain: ${ retry } ): ${ e } `
104
+ ) ;
105
+
106
+ if ( retry > 0 ) {
107
+ authorDetailAPITimeout = setTimeout ( ( ) => {
108
+ this . updateAuthorDetails ( retry - 1 ) . then (
109
+ ( ) => { } ,
110
+ ( ) => { }
111
+ ) ;
112
+ } , 1000 ) ;
113
+ } else {
114
+ this . updateIsSearching ( false ) ;
115
+ }
110
116
}
111
117
}
112
118
119
+ updateIsSearching ( isSearching : boolean ) {
120
+ const event = new CustomEvent < boolean > ( 'is-searching-changed' , {
121
+ bubbles : true ,
122
+ composed : true ,
123
+ detail : isSearching
124
+ } ) ;
125
+ this . dispatchEvent ( event ) ;
126
+ }
127
+
113
128
//==========================================================================||
114
129
// Templates and Styles ||
115
130
//==========================================================================||
0 commit comments