@@ -151,23 +151,21 @@ export default class LeftPanel extends React.PureComponent<Props, State> {
151
151
loadRandomPage = ( currentItems : Item [ ] ) => {
152
152
const { pages } = this . state
153
153
const { totalItems, totalCollections, onSetReviewedItems } = this . props
154
+
154
155
const totalResources = this . isCollectionTabActive ( ) ? totalCollections : totalItems
155
156
const totalPages = Math . ceil ( totalResources ! / LEFT_PANEL_PAGE_SIZE )
156
- if ( pages . length !== totalPages ) {
157
- let randomPage : number | undefined
158
- while ( randomPage === undefined ) {
159
- randomPage = this . getRandomPage ( 1 , totalPages )
160
- if ( pages . includes ( randomPage ) ) {
161
- randomPage = undefined
162
- }
163
- }
164
- onSetReviewedItems ( currentItems )
165
- if ( randomPage !== undefined ) {
166
- this . setState ( prevState => ( { pages : [ ...prevState . pages , randomPage as number ] } ) , this . fetchResource )
157
+
158
+ if ( totalPages > pages . length ) {
159
+ const availablePages = [ ...Array ( totalPages ) . keys ( ) ] . map ( i => i + 1 ) . filter ( page => ! pages . includes ( page ) )
160
+
161
+ if ( availablePages . length > 0 ) {
162
+ const randomPage = availablePages [ Math . floor ( Math . random ( ) * availablePages . length ) ]
163
+
164
+ this . setState ( prevState => ( { pages : [ ...prevState . pages , randomPage ] } ) , this . fetchResource )
167
165
}
168
- } else {
169
- onSetReviewedItems ( currentItems )
170
166
}
167
+
168
+ onSetReviewedItems ( currentItems )
171
169
}
172
170
173
171
handleTabChange = ( tab : ItemEditorTabs ) => {
0 commit comments