From 5dbf1aa8e09ba890f018a5bbd3537ff78db121b1 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Wed, 25 Dec 2024 02:36:53 +0100 Subject: [PATCH] Adjust ReaderChapterTransition text color Text color was never adjusted based on the selected "reader background color" --- src/lib/HelperFunctions.ts | 6 +++ .../viewer/ReaderTransitionPage.tsx | 44 ++++++++++++++++--- .../constants/ReaderSettings.constants.tsx | 10 ++--- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/lib/HelperFunctions.ts b/src/lib/HelperFunctions.ts index 9353b05c..d8a8a144 100644 --- a/src/lib/HelperFunctions.ts +++ b/src/lib/HelperFunctions.ts @@ -31,3 +31,9 @@ export const getErrorMessage = (error: unknown): string => { return `${error}`; }; + +export const getValueFromObject = (obj: Record, key: string): T => { + const keys = key.split('.'); + + return keys.reduce((acc, curr) => acc?.[curr], obj) as T; +}; diff --git a/src/modules/reader/components/viewer/ReaderTransitionPage.tsx b/src/modules/reader/components/viewer/ReaderTransitionPage.tsx index 94c8b3c2..4d7cdfb8 100644 --- a/src/modules/reader/components/viewer/ReaderTransitionPage.tsx +++ b/src/modules/reader/components/viewer/ReaderTransitionPage.tsx @@ -12,6 +12,7 @@ import { useTranslation } from 'react-i18next'; import Button from '@mui/material/Button'; import { Link } from 'react-router-dom'; import { memo } from 'react'; +import { alpha, useTheme } from '@mui/material/styles'; import { useReaderScrollbarContext } from '@/modules/reader/contexts/ReaderScrollbarContext.tsx'; import { useReaderStateChaptersContext } from '@/modules/reader/contexts/state/ReaderStateChaptersContext.tsx'; import { ChapterScanlatorInfo } from '@/modules/chapter/services/Chapters.ts'; @@ -37,26 +38,38 @@ import { AppRoutes } from '@/modules/core/AppRoute.constants.ts'; import { NavbarContextType } from '@/modules/navigation-bar/NavigationBar.types.ts'; import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx'; import { useReaderStateMangaContext } from '@/modules/reader/contexts/state/ReaderStateMangaContext.tsx'; +import { getValueFromObject } from '@/lib/HelperFunctions.ts'; +import { READER_BACKGROUND_TO_COLOR } from '@/modules/reader/constants/ReaderSettings.constants.tsx'; +import { ReaderService } from '@/modules/reader/services/ReaderService.ts'; const ChapterInfo = ({ title, chapter, + backgroundColor, }: { title: string; chapter?: Pick & ChapterScanlatorInfo; + backgroundColor: IReaderSettings['backgroundColor']; }) => { + const theme = useTheme(); + + const contrastText = theme.palette.getContrastText( + getValueFromObject(theme.palette, READER_BACKGROUND_TO_COLOR[backgroundColor]), + ); + const disabledText = alpha(contrastText, 0.5); + if (!chapter) { return null; } return ( - {title} - + {title} + {chapter.name} {chapter.scanlator && ( - + {chapter.scanlator} )} @@ -69,6 +82,7 @@ const BaseReaderTransitionPage = ({ mode, readingMode, pageScaleMode, + backgroundColor, manga, currentChapter, previousChapter, @@ -76,7 +90,7 @@ const BaseReaderTransitionPage = ({ scrollbarXSize, scrollbarYSize, readerNavBarWidth, -}: Pick & +}: Pick & Pick & Pick & Pick & @@ -158,7 +172,11 @@ const BaseReaderTransitionPage = ({ )} {isPreviousType && !isFirstChapter && ( - + )} {!!currentChapter && ( )} {isNextType && !isLastChapter && ( - + )} {isNextType && isLastChapter && ( @@ -207,7 +230,13 @@ const BaseReaderTransitionPage = ({ export const ReaderTransitionPage = withPropsFrom( memo(BaseReaderTransitionPage), - [useReaderStateMangaContext, useReaderStateChaptersContext, useReaderScrollbarContext, useNavBarContext], + [ + useReaderStateMangaContext, + useReaderStateChaptersContext, + useReaderScrollbarContext, + useNavBarContext, + ReaderService.useSettingsWithoutDefaultFlag, + ], [ 'manga', 'currentChapter', @@ -216,5 +245,6 @@ export const ReaderTransitionPage = withPropsFrom( 'scrollbarXSize', 'scrollbarYSize', 'readerNavBarWidth', + 'backgroundColor', ], ); diff --git a/src/modules/reader/constants/ReaderSettings.constants.tsx b/src/modules/reader/constants/ReaderSettings.constants.tsx index 0c9ee424..eb855bf6 100644 --- a/src/modules/reader/constants/ReaderSettings.constants.tsx +++ b/src/modules/reader/constants/ReaderSettings.constants.tsx @@ -254,9 +254,9 @@ export const READER_HOTKEYS = Object.values(ReaderHotkey).filter( (hotkey) => typeof hotkey === 'number', ) as ReaderHotkey[]; -export const READER_BACKGROUND_TO_COLOR: Record = { +export const READER_BACKGROUND_TO_COLOR = { [ReaderBackgroundColor.THEME]: 'background.default', - [ReaderBackgroundColor.BLACK]: 'black', - [ReaderBackgroundColor.GRAY]: 'gray', - [ReaderBackgroundColor.WHITE]: 'white', -}; + [ReaderBackgroundColor.BLACK]: 'common.black', + [ReaderBackgroundColor.GRAY]: 'grey.200', + [ReaderBackgroundColor.WHITE]: 'common.white', +} as const satisfies Record;