From 4b213b9429b88dcdd5f4879f3250c00703b5e2d1 Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 28 Oct 2024 22:59:00 +0100 Subject: [PATCH] Fix keyboard shortcuts for pagination --- .../app/reader/components/FoliateViewer.tsx | 11 +- .../app/reader/components/ReaderContent.tsx | 11 +- .../src/app/reader/components/SideBar.tsx | 145 +++++++++--------- 3 files changed, 88 insertions(+), 79 deletions(-) diff --git a/apps/readest-app/src/app/reader/components/FoliateViewer.tsx b/apps/readest-app/src/app/reader/components/FoliateViewer.tsx index 91be72b9..5ac24407 100644 --- a/apps/readest-app/src/app/reader/components/FoliateViewer.tsx +++ b/apps/readest-app/src/app/reader/components/FoliateViewer.tsx @@ -84,9 +84,18 @@ const FoliateViewer: React.FC<{ ); }; + const handleKeyboardPagination = (e: KeyboardEvent) => { + if (e.key === 'ArrowLeft' || e.key === 'PageUp' || e.key === 'h') { + view?.goLeft(); + } else if (e.key === 'ArrowRight' || e.key === 'PageDown' || e.key === 'l') { + view?.goRight(); + } + }; + const docLoadHandler = (event: Event) => { const detail = (event as CustomEvent).detail; - if (handleKeyDown) detail.doc?.addEventListener('keydown', handleKeyDown); + detail.doc?.addEventListener('keydown', handleKeyDown); + detail.doc?.addEventListener('keydown', handleKeyboardPagination); }; useFoliateEvents(view, { onLoad: docLoadHandler, onRelocate: progressRelocateHandler }); diff --git a/apps/readest-app/src/app/reader/components/ReaderContent.tsx b/apps/readest-app/src/app/reader/components/ReaderContent.tsx index 375502c5..ff9e8ac1 100644 --- a/apps/readest-app/src/app/reader/components/ReaderContent.tsx +++ b/apps/readest-app/src/app/reader/components/ReaderContent.tsx @@ -49,10 +49,15 @@ const ReaderContent = () => { return getKey(ids[nextIndex]!, nextIndex); }); e.preventDefault(); + } else if (e.key === 't') { + setSideBarVisibility((prev) => !prev); } - if (e.key === 'ArrowLeft') { + }; + + const handleKeyboardPagination = (e: KeyboardEvent) => { + if (e.key === 'ArrowLeft' || e.key === 'PageUp' || e.key === 'h') { getFoliateView(sideBarBookKey)?.goLeft(); - } else if (e.key === 'ArrowRight') { + } else if (e.key === 'ArrowRight' || e.key === 'PageDown' || e.key === 'l') { getFoliateView(sideBarBookKey)?.goRight(); } }; @@ -72,8 +77,10 @@ const ReaderContent = () => { useEffect(() => { window.addEventListener('keydown', handleKeyDown); + window.addEventListener('keydown', handleKeyboardPagination); return () => { window.removeEventListener('keydown', handleKeyDown); + window.removeEventListener('keydown', handleKeyboardPagination); }; }, [sideBarBookKey]); diff --git a/apps/readest-app/src/app/reader/components/SideBar.tsx b/apps/readest-app/src/app/reader/components/SideBar.tsx index a10e0a90..938c2bc0 100644 --- a/apps/readest-app/src/app/reader/components/SideBar.tsx +++ b/apps/readest-app/src/app/reader/components/SideBar.tsx @@ -1,4 +1,5 @@ import React, { useState, useEffect } from 'react'; +import clsx from 'clsx'; import { MdSearch, MdOutlinePushPin, @@ -79,86 +80,78 @@ const SideBar: React.FC<{ const { book, bookDoc } = bookState; - return ( - isVisible && ( -
-
-
-
- -
-
- - -
-
-
- -
-
- {activeTab === 'toc' && bookDoc!.toc && ( - - )} - {activeTab === 'bookmarks' &&
Bookmarks
} - {activeTab === 'annotations' &&
Annotations
} -
-
- - - +
+
+ +
-
- {!isPinned && ( -
handleClickOverlay()} - /> - )} +
+ +
+
+ {activeTab === 'toc' && bookDoc!.toc && ( + + )} + {activeTab === 'annotations' &&
Annotations
} + {activeTab === 'bookmarks' &&
Bookmarks
} +
+
+ {['toc', 'annotations', 'bookmarks'].map((tab) => ( + + ))} +
+
- ) - ); + {!isPinned && ( +
handleClickOverlay()} + /> + )} +
+ ) : null; }; export default SideBar;