@@ -28,6 +28,8 @@ const defaultQuotaOptions = {
2828 Unlimited : - 3 ,
2929}
3030
31+ const pageSize = 50
32+
3133export type SortKey = 'mount_point' | 'quota' | 'groups' | 'acl' ;
3234
3335export interface AppState {
@@ -45,6 +47,7 @@ export interface AppState {
4547 sortOrder : number ;
4648 isAdminNextcloud : boolean ;
4749 checkAppsInstalled : boolean ;
50+ currentPage : number ;
4851}
4952
5053export class App extends Component < unknown , AppState > implements OC . Plugin < OC . Search . Core > {
@@ -66,10 +69,12 @@ export class App extends Component<unknown, AppState> implements OC.Plugin<OC.Se
6669 sortOrder : 1 ,
6770 isAdminNextcloud : false ,
6871 checkAppsInstalled : false ,
72+ currentPage : 0 ,
6973 }
7074
7175 componentDidMount ( ) {
72- this . api . listFolders ( ) . then ( ( folders ) => {
76+ // list first pageSize + 1 folders so we know if there are more pages
77+ this . api . listFolders ( 0 , pageSize + 1 ) . then ( ( folders ) => {
7378 this . setState ( { folders } )
7479 } )
7580 this . api . listGroups ( ) . then ( ( groups ) => {
@@ -169,6 +174,21 @@ export class App extends Component<unknown, AppState> implements OC.Plugin<OC.Se
169174 this . api . setACL ( folder . id , acl )
170175 }
171176
177+ async goToPage ( page : number ) {
178+ const loadedPage = Math . floor ( this . state . folders . length / pageSize )
179+ if ( loadedPage <= page ) {
180+ const folders = await this . api . listFolders ( this . state . folders . length , ( page + 1 ) * pageSize - this . state . folders . length + 1 )
181+ this . setState ( {
182+ folders : [ ...this . state . folders , ...folders ] ,
183+ currentPage : page ,
184+ } )
185+ } else {
186+ this . setState ( {
187+ currentPage : page ,
188+ } )
189+ }
190+ }
191+
172192 onSortClick = ( sort : SortKey ) => {
173193 if ( this . state . sort === sort ) {
174194 this . setState ( { sortOrder : - this . state . sortOrder } )
@@ -361,6 +381,60 @@ export class App extends Component<unknown, AppState> implements OC.Plugin<OC.Se
361381 </ tr >
362382 </ FlipMove >
363383 </ table >
384+ < nav className = "groupfolders-pagination" aria-label = { t ( 'groupfolders' , 'Pagination of team folders' ) } >
385+ < ul className = "groupfolders-pagination__list" >
386+ < li >
387+ < button
388+ aria-label = { t ( 'groupfolders' , 'Previous' ) }
389+ className = "groupfolders-pagination__button"
390+ disabled = { this . state . currentPage === 0 }
391+ title = { t ( 'groupfolders' , 'Previous' ) }
392+ onClick = { ( ) => this . goToPage ( this . state . currentPage - 1 ) } > ⮜</ button >
393+ </ li >
394+ {
395+ // show the "1" button if we are not on the first page
396+ this . state . currentPage > 0 && < li > < button onClick = { ( ) => this . goToPage ( 0 ) } > 1</ button > </ li >
397+ }
398+ {
399+ // show the ellipsis button if there are more than 2 pages before the current
400+ this . state . currentPage > 2 && < li > < button disabled > …</ button > </ li > }
401+ {
402+ // show the page right before the current - if there is such a page
403+ this . state . currentPage > 1 && < li > < button onClick = { ( ) => this . goToPage ( this . state . currentPage - 1 ) } > { this . state . currentPage } </ button > </ li >
404+ }
405+ { /* the current page as a button */ }
406+ < li > < button aria-current = "page" aria-disabled className = "primary" > { this . state . currentPage + 1 } </ button > </ li >
407+ {
408+ // show the next page if it exists (we know at least that the next exists or not)
409+ ( this . state . currentPage + 1 ) < ( this . state . folders . length / pageSize )
410+ && < li >
411+ < button onClick = { ( ) => this . goToPage ( this . state . currentPage + 1 ) } > { this . state . currentPage + 2 } </ button >
412+ </ li >
413+ }
414+ {
415+ // If we know more than two next pages exist we show the ellipsis for the intermediate pages
416+ ( this . state . currentPage + 3 ) < ( this . state . folders . length / pageSize )
417+ && < li >
418+ < button disabled > …</ button >
419+ </ li >
420+ }
421+ {
422+ // If more than one next page exist we show the last page as a button
423+ ( this . state . currentPage + 2 ) < ( this . state . folders . length / pageSize )
424+ && < li >
425+ < button onClick = { ( ) => this . goToPage ( Math . floor ( this . state . folders . length / pageSize ) ) } > { Math . floor ( this . state . folders . length / pageSize ) + 1 } </ button >
426+ </ li >
427+ }
428+ < li >
429+ < button
430+ aria-label = { t ( 'groupfolders' , 'Next' ) }
431+ className = "groupfolders-pagination__button"
432+ disabled = { this . state . currentPage >= Math . floor ( this . state . folders . length / pageSize ) }
433+ title = { t ( 'groupfolders' , 'Next' ) }
434+ onClick = { ( ) => this . goToPage ( this . state . currentPage + 1 ) } > ⮞</ button >
435+ </ li >
436+ </ ul >
437+ </ nav >
364438 </ div >
365439 }
366440
0 commit comments