Reader progress bars
This commit is contained in:
@@ -6,16 +6,47 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { useMemo } from 'react';
|
||||
import { IReaderSettings } from '@/modules/reader/types/Reader.types.ts';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Direction, useTheme } from '@mui/material/styles';
|
||||
import { TChapterReader } from '@/modules/chapter/Chapter.types.ts';
|
||||
import { Chapters } from '@/modules/chapter/services/Chapters.ts';
|
||||
import { IReaderSettings, ReadingDirection } from '@/modules/reader/types/Reader.types.ts';
|
||||
import { useReaderStateMangaContext } from '@/modules/reader/contexts/state/ReaderStateMangaContext.tsx';
|
||||
import { getReaderSettingsFor, useDefaultReaderSettings } from '@/modules/reader/services/ReaderSettingsMetadata.ts';
|
||||
|
||||
const DIRECTION_TO_INVERTED: Record<Direction, Direction> = {
|
||||
ltr: 'rtl',
|
||||
rtl: 'ltr',
|
||||
};
|
||||
|
||||
const DIRECTION_TO_READING_DIRECTION: Record<Direction, ReadingDirection> = {
|
||||
ltr: ReadingDirection.LTR,
|
||||
rtl: ReadingDirection.RTL,
|
||||
};
|
||||
|
||||
export class ReaderService {
|
||||
static useNavigateToChapter(chapter?: TChapterReader): () => void {
|
||||
const navigate = useNavigate();
|
||||
|
||||
return useCallback(() => chapter && navigate(Chapters.getReaderUrl(chapter), { replace: true }), [chapter]);
|
||||
}
|
||||
|
||||
static useSettings(): IReaderSettings {
|
||||
const { manga } = useReaderStateMangaContext();
|
||||
const { settings } = useDefaultReaderSettings();
|
||||
const defaultReaderSettings = useDefaultReaderSettings();
|
||||
return useMemo(
|
||||
() => getReaderSettingsFor(manga ?? { id: -1 }, defaultReaderSettings.settings),
|
||||
[manga, defaultReaderSettings],
|
||||
);
|
||||
}
|
||||
|
||||
return useMemo(() => getReaderSettingsFor(manga ?? { id: -1 }, settings), [manga, settings]);
|
||||
static useGetThemeDirection(): Direction {
|
||||
const { direction } = useTheme();
|
||||
const { readingDirection } = ReaderService.useSettings();
|
||||
|
||||
return DIRECTION_TO_READING_DIRECTION[direction] === readingDirection
|
||||
? direction
|
||||
: DIRECTION_TO_INVERTED[direction];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user