Rename manga and chapter constants

This commit is contained in:
schroda
2025-05-05 01:46:11 +02:00
parent f0f740f4af
commit 18be295ef5
9 changed files with 24 additions and 21 deletions

View File

@@ -19,7 +19,7 @@ import { ComponentProps, useMemo } from 'react';
import LaunchIcon from '@mui/icons-material/Launch'; import LaunchIcon from '@mui/icons-material/Launch';
import { SelectableCollectionReturnType } from '@/modules/collection/hooks/useSelectableCollection.ts'; import { SelectableCollectionReturnType } from '@/modules/collection/hooks/useSelectableCollection.ts';
import { import {
actionToTranslationKey, CHAPTER_ACTION_TO_TRANSLATION,
ChapterAction, ChapterAction,
ChapterBookmarkInfo, ChapterBookmarkInfo,
ChapterDownloadInfo, ChapterDownloadInfo,
@@ -92,7 +92,7 @@ export const ChapterActionMenuItems = ({
settings: { deleteChaptersWithBookmark }, settings: { deleteChaptersWithBookmark },
} = useMetadataServerSettings(); } = useMetadataServerSettings();
const getMenuItemTitle = createGetMenuItemTitle(isSingleMode, actionToTranslationKey); const getMenuItemTitle = createGetMenuItemTitle(isSingleMode, CHAPTER_ACTION_TO_TRANSLATION);
const shouldShowMenuItem = createShouldShowMenuItem(isSingleMode); const shouldShowMenuItem = createShouldShowMenuItem(isSingleMode);
const isMenuItemDisabled = createIsMenuItemDisabled(isSingleMode); const isMenuItemDisabled = createIsMenuItemDisabled(isSingleMode);

View File

@@ -30,7 +30,7 @@ import { epochToDate, getDateString } from '@/util/DateHelper.ts';
export type ChapterAction = 'download' | 'delete' | 'bookmark' | 'unbookmark' | 'mark_as_read' | 'mark_as_unread'; export type ChapterAction = 'download' | 'delete' | 'bookmark' | 'unbookmark' | 'mark_as_read' | 'mark_as_unread';
export const actionToTranslationKey: { export const CHAPTER_ACTION_TO_TRANSLATION: {
[key in ChapterAction]: { [key in ChapterAction]: {
action: { action: {
single: TranslationKey; single: TranslationKey;
@@ -318,10 +318,10 @@ export class Chapters {
): Promise<void> { ): Promise<void> {
try { try {
await fnToExecute(); await fnToExecute();
makeToast(translate(actionToTranslationKey[action].success, { count: itemCount }), 'success'); makeToast(translate(CHAPTER_ACTION_TO_TRANSLATION[action].success, { count: itemCount }), 'success');
} catch (e) { } catch (e) {
makeToast( makeToast(
translate(actionToTranslationKey[action].error, { count: itemCount }), translate(CHAPTER_ACTION_TO_TRANSLATION[action].error, { count: itemCount }),
'error', 'error',
getErrorMessage(e), getErrorMessage(e),
); );

View File

@@ -28,7 +28,7 @@ import {
import { TranslationKey } from '@/Base.types.ts'; import { TranslationKey } from '@/Base.types.ts';
import { LibrarySortMode } from '@/modules/library/Library.types.ts'; import { LibrarySortMode } from '@/modules/library/Library.types.ts';
import { CategoryMetadataInfo } from '@/modules/category/Category.types.ts'; import { CategoryMetadataInfo } from '@/modules/category/Category.types.ts';
import { statusToTranslationKey } from '@/modules/manga/Manga.constants.ts'; import { MANGA_STATUS_TO_TRANSLATION } from '@/modules/manga/Manga.constants.ts';
import { GridLayout } from '@/modules/core/Core.types.ts'; import { GridLayout } from '@/modules/core/Core.types.ts';
import { getErrorMessage } from '@/lib/HelperFunctions.ts'; import { getErrorMessage } from '@/lib/HelperFunctions.ts';
@@ -113,7 +113,7 @@ export const LibraryOptionsPanel = ({
{Object.values(MangaStatus).map((status) => ( {Object.values(MangaStatus).map((status) => (
<ThreeStateCheckboxInput <ThreeStateCheckboxInput
key={status} key={status}
label={t(statusToTranslationKey[status])} label={t(MANGA_STATUS_TO_TRANSLATION[status])}
checked={categoryLibraryOptions.hasStatus[status]} checked={categoryLibraryOptions.hasStatus[status]}
onChange={(checked) => onChange={(checked) =>
updateCategoryLibraryOptions('hasStatus', { updateCategoryLibraryOptions('hasStatus', {

View File

@@ -16,7 +16,7 @@ export const GLOBAL_READER_SETTINGS_MANGA: MangaIdInfo = { id: -2 };
export const MANGA_COVER_ASPECT_RATIO = '1 / 1.5'; export const MANGA_COVER_ASPECT_RATIO = '1 / 1.5';
export const statusToTranslationKey: Record<MangaStatus, TranslationKey> = { export const MANGA_STATUS_TO_TRANSLATION: Record<MangaStatus, TranslationKey> = {
[MangaStatus.Cancelled]: 'manga.status.cancelled', [MangaStatus.Cancelled]: 'manga.status.cancelled',
[MangaStatus.Completed]: 'manga.status.completed', [MangaStatus.Completed]: 'manga.status.completed',
[MangaStatus.Licensed]: 'manga.status.licensed', [MangaStatus.Licensed]: 'manga.status.licensed',
@@ -26,7 +26,7 @@ export const statusToTranslationKey: Record<MangaStatus, TranslationKey> = {
[MangaStatus.Unknown]: 'manga.status.unknown', [MangaStatus.Unknown]: 'manga.status.unknown',
}; };
export const actionToTranslationKey: { export const MANGA_ACTION_TO_TRANSLATION: {
[key in MangaAction]: { [key in MangaAction]: {
action: { action: {
single: TranslationKey; single: TranslationKey;

View File

@@ -34,7 +34,7 @@ import { ChaptersDownloadActionMenuItems } from '@/modules/chapter/components/ac
import { NestedMenuItem } from '@/modules/core/components/menu/NestedMenuItem.tsx'; import { NestedMenuItem } from '@/modules/core/components/menu/NestedMenuItem.tsx';
import { MangaChapterStatFieldsFragment, MangaType } from '@/lib/graphql/generated/graphql.ts'; import { MangaChapterStatFieldsFragment, MangaType } from '@/lib/graphql/generated/graphql.ts';
import { MangaAction, MangaDownloadInfo, MangaIdInfo, MangaUnreadInfo } from '@/modules/manga/Manga.types.ts'; import { MangaAction, MangaDownloadInfo, MangaIdInfo, MangaUnreadInfo } from '@/modules/manga/Manga.types.ts';
import { actionToTranslationKey } from '@/modules/manga/Manga.constants.ts'; import { MANGA_ACTION_TO_TRANSLATION } from '@/modules/manga/Manga.constants.ts';
import { AppRoutes } from '@/modules/core/AppRoute.constants.ts'; import { AppRoutes } from '@/modules/core/AppRoute.constants.ts';
const ACTION_DISABLES_SELECTION_MODE: MangaAction[] = ['remove_from_library'] as const; const ACTION_DISABLES_SELECTION_MODE: MangaAction[] = ['remove_from_library'] as const;
@@ -68,7 +68,7 @@ export const MangaActionMenuItems = ({
const isSingleMode = !!manga; const isSingleMode = !!manga;
const selectedMangas = passedSelectedMangas ?? []; const selectedMangas = passedSelectedMangas ?? [];
const getMenuItemTitle = createGetMenuItemTitle(isSingleMode, actionToTranslationKey); const getMenuItemTitle = createGetMenuItemTitle(isSingleMode, MANGA_ACTION_TO_TRANSLATION);
const shouldShowMenuItem = createShouldShowMenuItem(isSingleMode); const shouldShowMenuItem = createShouldShowMenuItem(isSingleMode);
const isMenuItemDisabled = createIsMenuItemDisabled(isSingleMode); const isMenuItemDisabled = createIsMenuItemDisabled(isSingleMode);

View File

@@ -42,7 +42,7 @@ import { MangaType, SourceType } from '@/lib/graphql/generated/graphql.ts';
import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx'; import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx';
import { useResizeObserver } from '@/modules/core/hooks/useResizeObserver.tsx'; import { useResizeObserver } from '@/modules/core/hooks/useResizeObserver.tsx';
import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts'; import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
import { MANGA_COVER_ASPECT_RATIO, statusToTranslationKey } from '@/modules/manga/Manga.constants.ts'; import { MANGA_COVER_ASPECT_RATIO, MANGA_STATUS_TO_TRANSLATION } from '@/modules/manga/Manga.constants.ts';
import { MangaThumbnailInfo, MangaTrackRecordInfo } from '@/modules/manga/Manga.types.ts'; import { MangaThumbnailInfo, MangaTrackRecordInfo } from '@/modules/manga/Manga.types.ts';
import { TAppThemeContext, useAppThemeContext } from '@/modules/theme/contexts/AppThemeContext.tsx'; import { TAppThemeContext, useAppThemeContext } from '@/modules/theme/contexts/AppThemeContext.tsx';
import { applyStyles } from '@/modules/core/utils/ApplyStyles.ts'; import { applyStyles } from '@/modules/core/utils/ApplyStyles.ts';
@@ -418,7 +418,10 @@ export const MangaDetails = ({
</Stack> </Stack>
<Metadata title={t('manga.label.author')} value={getValueOrUnknown(manga.author)} /> <Metadata title={t('manga.label.author')} value={getValueOrUnknown(manga.author)} />
<Metadata title={t('manga.label.artist')} value={getValueOrUnknown(manga.artist)} /> <Metadata title={t('manga.label.artist')} value={getValueOrUnknown(manga.artist)} />
<Metadata title={t('manga.label.status')} value={t(statusToTranslationKey[manga.status])} /> <Metadata
title={t('manga.label.status')}
value={t(MANGA_STATUS_TO_TRANSLATION[manga.status])}
/>
<Metadata title={t('source.title_one')} value={getSourceName(manga.source)} /> <Metadata title={t('source.title_one')} value={getSourceName(manga.source)} />
</MetadataContainer> </MetadataContainer>
</ThumbnailMetadataWrapper> </ThumbnailMetadataWrapper>

View File

@@ -38,7 +38,7 @@ import {
MigrateMode, MigrateMode,
} from '@/modules/manga/Manga.types.ts'; } from '@/modules/manga/Manga.types.ts';
import { import {
actionToTranslationKey, MANGA_ACTION_TO_TRANSLATION,
MANGA_TAGS_BY_MANGA_TYPE, MANGA_TAGS_BY_MANGA_TYPE,
SOURCES_BY_MANGA_TYPE, SOURCES_BY_MANGA_TYPE,
} from '@/modules/manga/Manga.constants.ts'; } from '@/modules/manga/Manga.constants.ts';
@@ -494,10 +494,10 @@ export class Mangas {
): Promise<void> { ): Promise<void> {
try { try {
await fnToExecute(); await fnToExecute();
makeToast(translate(actionToTranslationKey[action].success, { count: itemCount }), 'success'); makeToast(translate(MANGA_ACTION_TO_TRANSLATION[action].success, { count: itemCount }), 'success');
} catch (e) { } catch (e) {
makeToast( makeToast(
translate(actionToTranslationKey[action].error, { count: itemCount }), translate(MANGA_ACTION_TO_TRANSLATION[action].error, { count: itemCount }),
'error', 'error',
getErrorMessage(e), getErrorMessage(e),
); );

View File

@@ -12,7 +12,7 @@ import { memo } from 'react';
import BookmarkIcon from '@mui/icons-material/Bookmark'; import BookmarkIcon from '@mui/icons-material/Bookmark';
import BookmarkBorderIcon from '@mui/icons-material/BookmarkBorder'; import BookmarkBorderIcon from '@mui/icons-material/BookmarkBorder';
import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx'; import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx';
import { actionToTranslationKey, ChapterAction, Chapters } from '@/modules/chapter/services/Chapters.ts'; import { CHAPTER_ACTION_TO_TRANSLATION, ChapterAction, Chapters } from '@/modules/chapter/services/Chapters.ts';
import { TChapterReader } from '@/modules/chapter/Chapter.types.ts'; import { TChapterReader } from '@/modules/chapter/Chapter.types.ts';
const BaseReaderBookmarkButton = ({ id, isBookmarked }: Pick<TChapterReader, 'id' | 'isBookmarked'>) => { const BaseReaderBookmarkButton = ({ id, isBookmarked }: Pick<TChapterReader, 'id' | 'isBookmarked'>) => {
@@ -21,7 +21,7 @@ const BaseReaderBookmarkButton = ({ id, isBookmarked }: Pick<TChapterReader, 'id
const bookmarkAction: Extract<ChapterAction, 'unbookmark' | 'bookmark'> = isBookmarked ? 'unbookmark' : 'bookmark'; const bookmarkAction: Extract<ChapterAction, 'unbookmark' | 'bookmark'> = isBookmarked ? 'unbookmark' : 'bookmark';
return ( return (
<CustomTooltip title={t(actionToTranslationKey[bookmarkAction].action.single)}> <CustomTooltip title={t(CHAPTER_ACTION_TO_TRANSLATION[bookmarkAction].action.single)}>
<IconButton onClick={() => Chapters.performAction(bookmarkAction, [id], {})} color="inherit"> <IconButton onClick={() => Chapters.performAction(bookmarkAction, [id], {})} color="inherit">
{isBookmarked ? <BookmarkIcon /> : <BookmarkBorderIcon />} {isBookmarked ? <BookmarkIcon /> : <BookmarkBorderIcon />}
</IconButton> </IconButton>

View File

@@ -15,7 +15,7 @@ import ReplayIcon from '@mui/icons-material/Replay';
import { memo, useMemo, useRef } from 'react'; import { memo, useMemo, useRef } from 'react';
import DeleteIcon from '@mui/icons-material/Delete'; import DeleteIcon from '@mui/icons-material/Delete';
import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx'; import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx';
import { actionToTranslationKey, Chapters } from '@/modules/chapter/services/Chapters.ts'; import { CHAPTER_ACTION_TO_TRANSLATION, Chapters } from '@/modules/chapter/services/Chapters.ts';
import { ReaderStateChapters } from '@/modules/reader/types/Reader.types.ts'; import { ReaderStateChapters } from '@/modules/reader/types/Reader.types.ts';
import { DownloadStateIndicator } from '@/modules/core/components/downloads/DownloadStateIndicator.tsx'; import { DownloadStateIndicator } from '@/modules/core/components/downloads/DownloadStateIndicator.tsx';
import { ReaderStatePages } from '@/modules/reader/types/ReaderProgressBar.types.ts'; import { ReaderStatePages } from '@/modules/reader/types/ReaderProgressBar.types.ts';
@@ -33,7 +33,7 @@ const DownloadButton = ({ currentChapter }: Required<Pick<ReaderStateChapters, '
if (currentChapter && Chapters.isDownloaded(currentChapter)) { if (currentChapter && Chapters.isDownloaded(currentChapter)) {
return ( return (
<CustomTooltip title={t(actionToTranslationKey.delete.action.single)}> <CustomTooltip title={t(CHAPTER_ACTION_TO_TRANSLATION.delete.action.single)}>
<IconButton onClick={() => Chapters.performAction('delete', [currentChapter.id], {})} color="inherit"> <IconButton onClick={() => Chapters.performAction('delete', [currentChapter.id], {})} color="inherit">
<DeleteIcon /> <DeleteIcon />
</IconButton> </IconButton>
@@ -46,7 +46,7 @@ const DownloadButton = ({ currentChapter }: Required<Pick<ReaderStateChapters, '
} }
return ( return (
<CustomTooltip title={t(actionToTranslationKey.download.action.single)} disabled={!currentChapter}> <CustomTooltip title={t(CHAPTER_ACTION_TO_TRANSLATION.download.action.single)} disabled={!currentChapter}>
<IconButton <IconButton
disabled={!currentChapter} disabled={!currentChapter}
onClick={() => Chapters.performAction('download', [currentChapter?.id ?? -1], {})} onClick={() => Chapters.performAction('download', [currentChapter?.id ?? -1], {})}