@@ -10,6 +10,7 @@ import BookmarksProvider from './bookmarks/bookmarks-provider.js';
1010import SharingProvider from './sharing.js' ;
1111import ViewableFilesProvider from './viewable-files.js' ;
1212import iaLogo from './assets/ia-logo.js' ;
13+ import { sortBy } from '../BookReader/utils.js' ;
1314/** @typedef {import('@/src/BookReader.js').default } BookReader */
1415
1516const events = {
@@ -51,7 +52,20 @@ export class BookNavigator extends LitElement {
5152 this . isAdmin = false ;
5253 this . lendingInitialized = false ;
5354 this . lendingStatus = { } ;
54- this . menuProviders = { } ;
55+ this . menuProviders = {
56+ /** @type {BookmarksProvider } */
57+ bookmarks : null ,
58+ /** @type {SearchProvider } */
59+ search : null ,
60+ /** @type {DownloadProvider } */
61+ downloads : null ,
62+ /** @type {VisualAdjustmentProvider } */
63+ visualAdjustments : null ,
64+ /** @type {SharingProvider } */
65+ share : null ,
66+ /** @type {ViewableFilesProvider } */
67+ volumes : null ,
68+ } ;
5569 this . menuShortcuts = [ ] ;
5670 this . signedIn = false ;
5771 /** @type {ModalManager } */
@@ -73,6 +87,10 @@ export class BookNavigator extends LitElement {
7387 'chapters' ,
7488 'search' ,
7589 'bookmarks' ,
90+ 'downloads' ,
91+ 'visualAdjustments' ,
92+ 'share' ,
93+ 'experiments' ,
7694 ] ;
7795 }
7896
@@ -313,14 +331,20 @@ export class BookNavigator extends LitElement {
313331 * Sets order of menu and emits custom event when done
314332 */
315333 updateMenuContents ( ) {
316- const {
317- search, downloads, visualAdjustments, share, bookmarks, volumes, chapters,
318- } = this . menuProviders ;
319- const availableMenus = [ volumes , chapters , search , bookmarks , visualAdjustments , share ] . filter ( ( menu ) => ! ! menu ) ;
334+ const availableMenus = sortBy (
335+ Object . entries ( this . menuProviders )
336+ . filter ( ( [ id , menu ] ) => ! ! menu )
337+ . filter ( ( [ id , menu ] ) => {
338+ return id === 'downloads' ? this . shouldShowDownloadsMenu ( ) : true ;
339+ } ) ,
340+ ( [ id , menu ] ) => {
341+ const index = this . shortcutOrder . indexOf ( id ) ;
342+ return index === - 1 ? this . shortcutOrder . length : index ;
343+ } ,
344+ ) . map ( ( [ id , menu ] ) => menu ) ;
320345
321346 if ( this . shouldShowDownloadsMenu ( ) ) {
322- downloads ?. update ( this . downloadableTypes ) ;
323- availableMenus . splice ( - 2 , 0 , downloads ) ;
347+ this . menuProviders . downloads ?. update ( this . downloadableTypes ) ;
324348 }
325349
326350 const event = new CustomEvent (
@@ -387,11 +411,13 @@ export class BookNavigator extends LitElement {
387411 * the id in each iteration over the shortcutOrder array.
388412 */
389413 sortMenuShortcuts ( ) {
390- this . menuShortcuts = this . shortcutOrder . reduce ( ( shortcuts , id ) => {
391- const menu = this . menuShortcuts . find ( ( m ) => m . id === id ) ;
392- if ( menu ) { shortcuts . push ( menu ) ; }
393- return shortcuts ;
394- } , [ ] ) ;
414+ this . menuShortcuts = sortBy (
415+ this . menuShortcuts ,
416+ ( shortcut ) => {
417+ const index = this . shortcutOrder . indexOf ( shortcut . id ) ;
418+ return index === - 1 ? this . shortcutOrder . length : index ;
419+ } ,
420+ ) ;
395421 }
396422
397423 emitMenuShortcutsUpdated ( ) {
0 commit comments