Add chapter action to open chapter on source (#634)

This commit is contained in:
schroda
2024-03-02 16:11:39 +01:00
committed by GitHub
parent 8bdf035ca7
commit fb0622e209
3 changed files with 16 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ import BookmarkRemove from '@mui/icons-material/BookmarkRemove';
import BookmarkAdd from '@mui/icons-material/BookmarkAdd'; import BookmarkAdd from '@mui/icons-material/BookmarkAdd';
import DoneAll from '@mui/icons-material/DoneAll'; import DoneAll from '@mui/icons-material/DoneAll';
import { useMemo } from 'react'; import { useMemo } from 'react';
import PublicIcon from '@mui/icons-material/Public';
import { SelectableCollectionReturnType } from '@/components/collection/useSelectableCollection.ts'; import { SelectableCollectionReturnType } from '@/components/collection/useSelectableCollection.ts';
import { import {
actionToTranslationKey, actionToTranslationKey,
@@ -23,6 +24,7 @@ import {
ChapterBookmarkInfo, ChapterBookmarkInfo,
ChapterDownloadInfo, ChapterDownloadInfo,
ChapterReadInfo, ChapterReadInfo,
ChapterRealUrlInfo,
Chapters, Chapters,
} from '@/lib/data/Chapters.ts'; } from '@/lib/data/Chapters.ts';
import { TChapter } from '@/typings.ts'; import { TChapter } from '@/typings.ts';
@@ -35,7 +37,7 @@ import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts
type BaseProps = { onClose: () => void }; type BaseProps = { onClose: () => void };
type SingleModeProps = { type SingleModeProps = {
chapter: ChapterDownloadInfo & ChapterBookmarkInfo & ChapterReadInfo; chapter: ChapterDownloadInfo & ChapterBookmarkInfo & ChapterReadInfo & ChapterRealUrlInfo;
allChapters: TChapter[]; allChapters: TChapter[];
handleSelection?: SelectableCollectionReturnType<TChapter['id']>['handleSelection']; handleSelection?: SelectableCollectionReturnType<TChapter['id']>['handleSelection'];
canBeDownloaded: boolean; canBeDownloaded: boolean;
@@ -126,6 +128,17 @@ export const ChapterActionMenuItems = ({
{isSingleMode && ( {isSingleMode && (
<MenuItem onClick={handleSelect} Icon={CheckBoxOutlineBlank} title={t('chapter.action.label.select')} /> <MenuItem onClick={handleSelect} Icon={CheckBoxOutlineBlank} title={t('chapter.action.label.select')} />
)} )}
{isSingleMode && (
<MenuItem
Icon={PublicIcon}
disabled={!chapter!.realUrl}
onClick={() => {
window.open(chapter!.realUrl!, '_blank', 'noopener,noreferrer');
onClose();
}}
title={t('chapter.action.label.open_on_source')}
/>
)}
{shouldShowMenuItem(canBeDownloaded) && ( {shouldShowMenuItem(canBeDownloaded) && (
<MenuItem <MenuItem
Icon={Download} Icon={Download}

View File

@@ -90,6 +90,7 @@
} }
}, },
"label": { "label": {
"open_on_source": "Open on source",
"select": "Select" "select": "Select"
}, },
"mark_as_read": { "mark_as_read": {

View File

@@ -83,6 +83,7 @@ export type ChapterBookmarkInfo = ChapterIdInfo & Pick<TChapter, 'isBookmarked'>
export type ChapterReadInfo = ChapterIdInfo & Pick<TChapter, 'isRead'>; export type ChapterReadInfo = ChapterIdInfo & Pick<TChapter, 'isRead'>;
export type ChapterNumberInfo = ChapterIdInfo & Pick<TChapter, 'chapterNumber'>; export type ChapterNumberInfo = ChapterIdInfo & Pick<TChapter, 'chapterNumber'>;
export type ChapterScanlatorInfo = ChapterIdInfo & Pick<TChapter, 'scanlator'>; export type ChapterScanlatorInfo = ChapterIdInfo & Pick<TChapter, 'scanlator'>;
export type ChapterRealUrlInfo = Pick<TChapter, 'realUrl'>;
export class Chapters { export class Chapters {
static getIds(chapters: { id: number }[]): number[] { static getIds(chapters: { id: number }[]): number[] {