@@ -8,7 +8,11 @@
|
||||
|
||||
import { MangaStatus } from '@/lib/graphql/generated/graphql.ts';
|
||||
import { TranslationKey } from '@/Base.types.ts';
|
||||
import { MangaAction } from '@/modules/manga/Manga.types.ts';
|
||||
import { MangaAction, MangaIdInfo } from '@/modules/manga/Manga.types.ts';
|
||||
|
||||
export const FALLBACK_MANGA: MangaIdInfo = { id: -1 };
|
||||
|
||||
export const GLOBAL_READER_SETTINGS_MANGA: MangaIdInfo = { id: -2 };
|
||||
|
||||
export const MANGA_COVER_ASPECT_RATIO = '1 / 1.5';
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ import {
|
||||
READING_MODE_VALUES,
|
||||
} from '@/modules/reader/constants/ReaderSettings.constants.tsx';
|
||||
import { useReaderStateMangaContext } from '@/modules/reader/contexts/state/ReaderStateMangaContext.tsx';
|
||||
import { MangaIdInfo } from '@/modules/manga/Manga.types.ts';
|
||||
import { HotkeyScope } from '@/modules/hotkeys/Hotkeys.types.ts';
|
||||
import { ReaderControls } from '@/modules/reader/services/ReaderControls.ts';
|
||||
import { ScrollDirection, ScrollOffset } from '@/modules/core/Core.types.ts';
|
||||
import { getOptionForDirection } from '@/modules/theme/services/ThemeCreator.ts';
|
||||
import { FALLBACK_MANGA } from '@/modules/manga/Manga.constants.ts';
|
||||
|
||||
const useHotkeys = (...args: Parameters<typeof useHotKeysHook>): ReturnType<typeof useHotKeysHook> => {
|
||||
const [keys, callback, options, dependencies] = args;
|
||||
@@ -57,8 +57,6 @@ const updateSettingCycleThrough = <Setting extends keyof IReaderSettings>(
|
||||
updateSetting(setting, nextValue);
|
||||
};
|
||||
|
||||
const DEFAULT_MANGA: MangaIdInfo = { id: -1 };
|
||||
|
||||
const CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION: Record<ReadingMode, ScrollDirection> = {
|
||||
[ReadingMode.SINGLE_PAGE]: ScrollDirection.Y,
|
||||
[ReadingMode.DOUBLE_PAGE]: ScrollDirection.Y,
|
||||
@@ -83,8 +81,8 @@ export const ReaderHotkeys = ({
|
||||
const openChapter = ReaderControls.useOpenChapter();
|
||||
const openPage = ReaderControls.useOpenPage();
|
||||
|
||||
const updateSetting = ReaderService.useCreateUpdateSetting(manga ?? DEFAULT_MANGA);
|
||||
const deleteSetting = ReaderService.useCreateDeleteSetting(manga ?? DEFAULT_MANGA);
|
||||
const updateSetting = ReaderService.useCreateUpdateSetting(manga ?? FALLBACK_MANGA);
|
||||
const deleteSetting = ReaderService.useCreateDeleteSetting(manga ?? FALLBACK_MANGA);
|
||||
|
||||
useHotkeys(hotkeys[ReaderHotkey.PREVIOUS_PAGE], () => openPage('previous'), [openPage]);
|
||||
useHotkeys(hotkeys[ReaderHotkey.NEXT_PAGE], () => openPage('next'), [openPage]);
|
||||
|
||||
@@ -31,10 +31,10 @@ import { userReaderStatePagesContext } from '@/modules/reader/contexts/state/Rea
|
||||
import { useReaderStateChaptersContext } from '@/modules/reader/contexts/state/ReaderStateChaptersContext.tsx';
|
||||
import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
|
||||
import { LoadingPlaceholder } from '@/modules/core/components/placeholder/LoadingPlaceholder.tsx';
|
||||
import { MangaIdInfo } from '@/modules/manga/Manga.types.ts';
|
||||
import { NavbarContextType } from '@/modules/navigation-bar/NavigationBar.types.ts';
|
||||
import { IReaderSettings, ReaderStateChapters, TReaderStateMangaContext } from '@/modules/reader/types/Reader.types.ts';
|
||||
import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx';
|
||||
import { FALLBACK_MANGA } from '@/modules/manga/Manga.constants.ts';
|
||||
|
||||
const useGetPreviousNavBarStaticValue = (isVisible: boolean, isStaticNav: boolean) => {
|
||||
const wasNavBarStaticRef = useRef(isStaticNav);
|
||||
@@ -54,7 +54,6 @@ const useGetPreviousNavBarStaticValue = (isVisible: boolean, isStaticNav: boolea
|
||||
return wasNavBarStaticRef.current;
|
||||
};
|
||||
|
||||
const DEFAULT_MANGA: MangaIdInfo = { id: -1 };
|
||||
const BaseReaderNavBarDesktop = ({
|
||||
isVisible,
|
||||
openSettings,
|
||||
@@ -77,7 +76,7 @@ const BaseReaderNavBarDesktop = ({
|
||||
|
||||
const getOptionForDirection = useGetOptionForDirection();
|
||||
|
||||
const updateReaderSettings = ReaderService.useCreateUpdateSetting(manga ?? DEFAULT_MANGA);
|
||||
const updateReaderSettings = ReaderService.useCreateUpdateSetting(manga ?? FALLBACK_MANGA);
|
||||
|
||||
const [navBarElement, setNavBarElement] = useState<HTMLDivElement | null>();
|
||||
useResizeObserver(
|
||||
|
||||
@@ -17,11 +17,10 @@ import { ReaderNavBarDesktopReadingDirection } from '@/modules/reader/components
|
||||
import { IReaderSettingsWithDefaultFlag, TReaderStateMangaContext } from '@/modules/reader/types/Reader.types.ts';
|
||||
import { ReaderNavBarDesktopProps } from '@/modules/reader/types/ReaderOverlay.types.ts';
|
||||
import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
|
||||
import { MangaIdInfo } from '@/modules/manga/Manga.types.ts';
|
||||
import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx';
|
||||
import { useReaderStateMangaContext } from '@/modules/reader/contexts/state/ReaderStateMangaContext.tsx';
|
||||
import { FALLBACK_MANGA } from '@/modules/manga/Manga.constants.ts';
|
||||
|
||||
const DEFAULT_MANGA: MangaIdInfo = { id: -1 };
|
||||
const BaseReaderNavBarDesktopQuickSettings = ({
|
||||
manga,
|
||||
readingMode,
|
||||
@@ -38,8 +37,8 @@ const BaseReaderNavBarDesktopQuickSettings = ({
|
||||
>) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const updateSetting = ReaderService.useCreateUpdateSetting(manga ?? DEFAULT_MANGA);
|
||||
const deleteSetting = ReaderService.useCreateDeleteSetting(manga ?? DEFAULT_MANGA);
|
||||
const updateSetting = ReaderService.useCreateUpdateSetting(manga ?? FALLBACK_MANGA);
|
||||
const deleteSetting = ReaderService.useCreateDeleteSetting(manga ?? FALLBACK_MANGA);
|
||||
|
||||
return (
|
||||
<Stack sx={{ gap: 1 }}>
|
||||
|
||||
@@ -12,19 +12,18 @@ import { ReaderSettingReadingMode } from '@/modules/reader/components/settings/l
|
||||
import { ReaderSettingReadingDirection } from '@/modules/reader/components/settings/layout/ReaderSettingReadingDirection.tsx';
|
||||
import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
|
||||
import { useReaderStateMangaContext } from '@/modules/reader/contexts/state/ReaderStateMangaContext.tsx';
|
||||
import { MangaIdInfo } from '@/modules/manga/Manga.types.ts';
|
||||
import { DefaultSettingFootnote } from '@/modules/reader/components/settings/DefaultSettingFootnote.tsx';
|
||||
import { IReaderSettingsWithDefaultFlag, TReaderStateMangaContext } from '@/modules/reader/types/Reader.types.ts';
|
||||
import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx';
|
||||
import { FALLBACK_MANGA } from '@/modules/manga/Manga.constants.ts';
|
||||
|
||||
const DEFAULT_MANGA: MangaIdInfo = { id: -1 };
|
||||
const BaseReaderBottomBarMobileQuickSettings = ({
|
||||
manga,
|
||||
readingMode,
|
||||
readingDirection,
|
||||
}: Pick<TReaderStateMangaContext, 'manga'> &
|
||||
Pick<IReaderSettingsWithDefaultFlag, 'readingMode' | 'readingDirection'>) => {
|
||||
const deleteSetting = ReaderService.useCreateDeleteSetting(manga ?? DEFAULT_MANGA);
|
||||
const deleteSetting = ReaderService.useCreateDeleteSetting(manga ?? FALLBACK_MANGA);
|
||||
|
||||
if (!manga) {
|
||||
return null;
|
||||
|
||||
@@ -17,6 +17,7 @@ import { IReaderSettings, ReadingMode } from '@/modules/reader/types/Reader.type
|
||||
import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
|
||||
import { ReaderSettingsTabs } from '@/modules/reader/components/settings/ReaderSettingsTabs.tsx';
|
||||
import { getErrorMessage } from '@/lib/HelperFunctions.ts';
|
||||
import { GLOBAL_READER_SETTINGS_MANGA } from '@/modules/manga/Manga.constants.ts';
|
||||
|
||||
export const GlobalReaderSettings = () => {
|
||||
const { t } = useTranslation();
|
||||
@@ -45,7 +46,7 @@ export const GlobalReaderSettings = () => {
|
||||
commit?: boolean,
|
||||
profile?: ReadingMode,
|
||||
) => {
|
||||
ReaderService.updateSetting({ id: -1 }, key, value, commit, true, profile);
|
||||
ReaderService.updateSetting(GLOBAL_READER_SETTINGS_MANGA, key, value, commit, true, profile);
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
@@ -69,7 +70,7 @@ export const GlobalReaderSettings = () => {
|
||||
areDefaultSettings
|
||||
settings={settings}
|
||||
updateSetting={(setting, value, commit, _, profile) => updateSetting(setting, value, commit, profile)}
|
||||
deleteSetting={(setting) => ReaderService.deleteSetting({ id: -1 }, setting, true)}
|
||||
deleteSetting={(setting) => ReaderService.deleteSetting(GLOBAL_READER_SETTINGS_MANGA, setting, true)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -52,6 +52,7 @@ import { TReaderOverlayContext } from '@/modules/reader/types/ReaderOverlay.type
|
||||
import { ReaderStatePages } from '@/modules/reader/types/ReaderProgressBar.types.ts';
|
||||
import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx';
|
||||
import { useReaderStateChaptersContext } from '@/modules/reader/contexts/state/ReaderStateChaptersContext.tsx';
|
||||
import { FALLBACK_MANGA } from '@/modules/manga/Manga.constants.ts';
|
||||
|
||||
const BaseReader = ({
|
||||
setTitle,
|
||||
@@ -225,7 +226,7 @@ const BaseReader = ({
|
||||
}
|
||||
|
||||
const settingsWithDefaultProfileFallback = getReaderSettingsFor(
|
||||
mangaResponse.data?.manga ?? { id: -1 },
|
||||
mangaResponse.data?.manga ?? FALLBACK_MANGA,
|
||||
defaultSettings,
|
||||
);
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts'
|
||||
import { Queue } from '@/lib/Queue.ts';
|
||||
import { AppRoutes } from '@/modules/core/AppRoute.constants.ts';
|
||||
import { getErrorMessage } from '@/lib/HelperFunctions.ts';
|
||||
import { FALLBACK_MANGA } from '@/modules/manga/Manga.constants.ts';
|
||||
|
||||
const DIRECTION_TO_INVERTED: Record<Direction, Direction> = {
|
||||
ltr: 'rtl',
|
||||
@@ -241,7 +242,7 @@ export class ReaderService {
|
||||
isGlobal: boolean = false,
|
||||
profile?: ReadingMode,
|
||||
): void {
|
||||
if (!manga || manga.id === -1) {
|
||||
if (!manga || manga.id === FALLBACK_MANGA.id) {
|
||||
return;
|
||||
}
|
||||
const key = getMetadataKey(setting, profile !== undefined ? [profile?.toString()] : undefined);
|
||||
@@ -305,7 +306,7 @@ export class ReaderService {
|
||||
isGlobal: boolean = false,
|
||||
profile?: string,
|
||||
): void {
|
||||
if (!manga || manga.id === -1) {
|
||||
if (!manga || manga.id === FALLBACK_MANGA.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user