@@ -12,6 +12,8 @@ export function loadAuthorList() {
1212 } ) ;
1313}
1414
15+ const PAGE_SIZE = 12 ;
16+
1517function loadAuthorListForLetter ( letter : string ) {
1618 const activeAuthors : Author [ ] = JSON . parse (
1719 localStorage . getItem ( "activeAuthors" ) ?? "" ,
@@ -24,36 +26,22 @@ function loadAuthorListForLetter(letter: string) {
2426 displayCarousel ( filteredAuthors ) ;
2527}
2628
27- /*
28- * Sort by number of posts descending, then by name
29- */
30- function compareAuthor ( a : Author , b : Author ) {
31- if ( a . postCount > b . postCount ) {
32- return - 1 ;
33- }
34- if ( a . postCount < b . postCount ) {
35- return 1 ;
36- }
37- return a . name . localeCompare ( b . name ) ;
38- }
39-
4029function displayCarousel ( authorList : Author [ ] ) {
4130 authorList . sort ( compareAuthor ) ;
4231
43- const pageSize = 12 ;
44- const pageCount = Math . floor ( authorList . length / pageSize ) ;
45- const remainder = authorList . length % pageSize ;
32+ const pageCount = Math . floor ( authorList . length / PAGE_SIZE ) ;
33+ const remainder = authorList . length % PAGE_SIZE ;
4634
4735 for ( let i = 0 ; i < pageCount ; i ++ ) {
48- const start = i * pageSize ;
49- const end = ( i + 1 ) * pageSize ;
36+ const start = i * PAGE_SIZE ;
37+ const end = ( i + 1 ) * PAGE_SIZE ;
5038
5139 const authorsForPage = authorList . slice ( start , end ) ;
5240 displayPage ( i , authorsForPage ) ;
5341 }
5442
5543 if ( remainder ) {
56- const start = pageCount * pageSize ;
44+ const start = pageCount * PAGE_SIZE ;
5745 const end = authorList . length ;
5846
5947 const authorsForPage = authorList . slice ( start , end ) ;
@@ -203,3 +191,16 @@ interface Author {
203191 postCount : number ;
204192 isActive : boolean ;
205193}
194+
195+ /*
196+ * Sort by number of posts descending, then by name
197+ */
198+ function compareAuthor ( a : Author , b : Author ) {
199+ if ( a . postCount > b . postCount ) {
200+ return - 1 ;
201+ }
202+ if ( a . postCount < b . postCount ) {
203+ return 1 ;
204+ }
205+ return a . name . localeCompare ( b . name ) ;
206+ }
0 commit comments