Feature/download ahead while reading (#464)
* Download next chapters when marking chapter as read while reading * Add "auto delete chapter" settings * Delete chapter after finished reading * Delete chapters after marking them as read * Improve "mark previous as read" action Send only ids of chapters that are actually unread
This commit is contained in:
@@ -22,6 +22,7 @@ import { ChaptersToolbarMenu } from '@/components/manga/ChaptersToolbarMenu';
|
||||
import { SelectionFAB } from '@/components/manga/SelectionFAB';
|
||||
import { DEFAULT_FULL_FAB_HEIGHT } from '@/components/util/StyledFab';
|
||||
import { DownloadType, UpdateChapterPatchInput } from '@/lib/graphql/generated/graphql.ts';
|
||||
import { useMetadataServerSettings } from '@/util/metadataServerSettings.ts';
|
||||
|
||||
const StyledVirtuoso = styled(Virtuoso)(({ theme }) => ({
|
||||
listStyle: 'none',
|
||||
@@ -89,7 +90,8 @@ export const ChapterList: React.FC<IProps> = ({ manga, isRefreshing }) => {
|
||||
const [options, dispatch] = useChapterOptions(manga.id);
|
||||
const { data: chaptersData, loading: isLoading, refetch } = requestManager.useGetMangaChapters(manga.id);
|
||||
const chapters = useMemo(() => chaptersData?.chapters.nodes ?? [], [chaptersData?.chapters.nodes]);
|
||||
const mangaChapterIds = useMemo(() => chapters.map((chapter) => chapter.id), [chapters]);
|
||||
|
||||
const { settings: metadataServerSettings } = useMetadataServerSettings();
|
||||
|
||||
useEffect(() => {
|
||||
if (prevQueueRef.current && queue) {
|
||||
@@ -164,6 +166,20 @@ export const ChapterList: React.FC<IProps> = ({ manga, isRefreshing }) => {
|
||||
} else {
|
||||
actionPromise = requestManager.updateChapters(chapterIds, change).response;
|
||||
}
|
||||
|
||||
const shouldDeleteChapters =
|
||||
action === 'mark_as_read' && metadataServerSettings.deleteChaptersManuallyMarkedRead;
|
||||
if (shouldDeleteChapters) {
|
||||
const chapterIdsToDelete = actionChapters
|
||||
.filter(
|
||||
({ chapter }) =>
|
||||
chapter.isDownloaded &&
|
||||
(!chapter.isBookmarked || metadataServerSettings.deleteChaptersWithBookmark),
|
||||
)
|
||||
.map(({ chapter }) => chapter.id);
|
||||
|
||||
requestManager.deleteDownloadedChapters(chapterIdsToDelete).response.catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
actionPromise
|
||||
@@ -285,7 +301,7 @@ export const ChapterList: React.FC<IProps> = ({ manga, isRefreshing }) => {
|
||||
return (
|
||||
<ChapterCard
|
||||
{...chaptersWithMeta[index]}
|
||||
chapterIds={mangaChapterIds}
|
||||
allChapters={chapters}
|
||||
showChapterNumber={options.showChapterNumber}
|
||||
onSelect={() => handleSelection(index)}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user