diff --git a/apps/readest-app/src/app/reader/components/BooksGrid.tsx b/apps/readest-app/src/app/reader/components/BooksGrid.tsx index 87185bed..a46526f6 100644 --- a/apps/readest-app/src/app/reader/components/BooksGrid.tsx +++ b/apps/readest-app/src/app/reader/components/BooksGrid.tsx @@ -14,7 +14,7 @@ import SettingsDialog from '@/components/settings/SettingsDialog'; import FoliateViewer from './FoliateViewer'; import SectionInfo from './SectionInfo'; import HeaderBar from './HeaderBar'; -import FooterBar from './FooterBar'; +import FooterBar from './footerbar/FooterBar'; import ProgressInfoView from './ProgressInfo'; import Ribbon from './Ribbon'; import Annotator from './annotator/Annotator'; diff --git a/apps/readest-app/src/app/reader/components/FooterBar.tsx b/apps/readest-app/src/app/reader/components/FooterBar.tsx deleted file mode 100644 index dce6b184..00000000 --- a/apps/readest-app/src/app/reader/components/FooterBar.tsx +++ /dev/null @@ -1,422 +0,0 @@ -import React, { useEffect } from 'react'; -import clsx from 'clsx'; -import { RiArrowLeftSLine, RiArrowRightSLine } from 'react-icons/ri'; -import { RiArrowGoBackLine, RiArrowGoForwardLine } from 'react-icons/ri'; -import { RiArrowLeftDoubleLine, RiArrowRightDoubleLine } from 'react-icons/ri'; -import { FaHeadphones } from 'react-icons/fa6'; -import { IoIosList as TOCIcon } from 'react-icons/io'; -import { PiNotePencil as NoteIcon } from 'react-icons/pi'; -import { RxSlider as SliderIcon } from 'react-icons/rx'; -import { RiFontFamily as FontIcon } from 'react-icons/ri'; -import { MdOutlineHeadphones as TTSIcon } from 'react-icons/md'; -import { TbBoxMargin } from 'react-icons/tb'; -import { RxLineHeight } from 'react-icons/rx'; - -import { useEnv } from '@/context/EnvContext'; -import { useReaderStore } from '@/store/readerStore'; -import { useSidebarStore } from '@/store/sidebarStore'; -import { useBookDataStore } from '@/store/bookDataStore'; -import { useTranslation } from '@/hooks/useTranslation'; -import { useResponsiveSize } from '@/hooks/useResponsiveSize'; -import { saveViewSettings } from '@/helpers/viewSettings'; -import { eventDispatcher } from '@/utils/event'; -import { viewPagination } from '../hooks/usePagination'; -import { PageInfo } from '@/types/book'; -import { Insets } from '@/types/misc'; -import Button from '@/components/Button'; -import Slider from '@/components/Slider'; -import TTSControl from './tts/TTSControl'; - -interface FooterBarProps { - bookKey: string; - bookFormat: string; - section?: PageInfo; - pageinfo?: PageInfo; - isHoveredAnim: boolean; - gridInsets: Insets; -} - -const FooterBar: React.FC = ({ - bookKey, - bookFormat, - section, - pageinfo, - isHoveredAnim, - gridInsets, -}) => { - const _ = useTranslation(); - const { envConfig, appService } = useEnv(); - const { getConfig, setConfig } = useBookDataStore(); - const { hoveredBookKey, setHoveredBookKey } = useReaderStore(); - const { getView, getViewState, getProgress, getViewSettings } = useReaderStore(); - const { isSideBarVisible, setSideBarVisible } = useSidebarStore(); - const [actionTab, setActionTab] = React.useState(''); - const sliderHeight = useResponsiveSize(28); - const tocIconSize = useResponsiveSize(23); - const fontIconSize = useResponsiveSize(18); - const marginIconSize = useResponsiveSize(20); - - const view = getView(bookKey); - const config = getConfig(bookKey); - const progress = getProgress(bookKey); - const viewSettings = getViewSettings(bookKey); - const viewState = getViewState(bookKey); - - const handleProgressChange = (value: number) => { - view?.goToFraction(value / 100.0); - }; - - const handleFontSizeChange = (value: number) => { - saveViewSettings(envConfig, bookKey, 'defaultFontSize', value); - }; - - const handleMarginChange = (value: number) => { - const viewSettings = getViewSettings(bookKey)!; - const marginPx = Math.round((value / 100) * 88); - const gapPercent = Math.round((value / 100) * 10); - viewSettings.marginTopPx = marginPx; - viewSettings.marginBottomPx = marginPx / 2; - viewSettings.marginLeftPx = marginPx / 2; - viewSettings.marginRightPx = marginPx / 2; - saveViewSettings(envConfig, bookKey, 'gapPercent', gapPercent, false, false); - view?.renderer.setAttribute('margin', `${marginPx}px`); - view?.renderer.setAttribute('gap', `${gapPercent}%`); - if (viewSettings?.scrolled) { - view?.renderer.setAttribute('flow', 'scrolled'); - } - }; - - const handleLineHeightChange = (value: number) => { - saveViewSettings(envConfig, bookKey, 'lineHeight', value / 10); - }; - - const handleGoPrevPage = () => { - viewPagination(view, viewSettings, 'left'); - }; - - const handleGoNextPage = () => { - viewPagination(view, viewSettings, 'right'); - }; - - const handleGoPrevSection = () => { - if (view?.renderer.prevSection) { - view?.renderer.prevSection(); - } - }; - - const handleGoNextSection = () => { - if (view?.renderer.nextSection) { - view?.renderer.nextSection(); - } - }; - - const handleGoBack = () => { - view?.history.back(); - }; - - const handleGoForward = () => { - view?.history.forward(); - }; - - const handleSpeakText = async () => { - if (!view || !progress || !viewState) return; - if (viewState.ttsEnabled) { - eventDispatcher.dispatch('tts-stop', { bookKey }); - } else { - eventDispatcher.dispatch('tts-speak', { bookKey }); - } - }; - - const handleSetActionTab = (tab: string) => { - setActionTab(actionTab === tab ? '' : tab); - if (tab === 'tts') { - setHoveredBookKey(''); - handleSpeakText(); - } else if (tab === 'toc') { - setHoveredBookKey(''); - if (config && config.viewSettings) { - config.viewSettings.sideBarTab = 'toc'; - setConfig(bookKey, config); - } - setSideBarVisible(true); - } else if (tab === 'note') { - setHoveredBookKey(''); - setSideBarVisible(true); - if (config && config.viewSettings) { - config.viewSettings.sideBarTab = 'annotations'; - setConfig(bookKey, config); - } - } - }; - - useEffect(() => { - if (hoveredBookKey !== bookKey) { - setActionTab(''); - } - }, [hoveredBookKey, bookKey]); - - const getMarginProgressValue = (marginPx: number, gapPercent: number) => { - return (marginPx / 88 + gapPercent / 10) * 50; - }; - - const isVisible = hoveredBookKey === bookKey; - const ttsEnabled = viewState?.ttsEnabled; - const progressInfo = bookFormat === 'PDF' ? section : pageinfo; - const progressValid = !!progressInfo; - const progressFraction = - progressValid && progressInfo?.total > 0 - ? (progressInfo!.current + 1) / progressInfo!.total || 0 - : 0; - - const isMobile = window.innerWidth < 640 || window.innerHeight < 640; - - return ( - <> -