From 90cec353586f557337f2450f5067ab15a94a2275 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Mon, 18 Dec 2023 21:40:56 +0100 Subject: [PATCH] Add button to quickly select all chapters --- src/components/manga/ChapterList.tsx | 73 ++++++++++++++++------------ 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/src/components/manga/ChapterList.tsx b/src/components/manga/ChapterList.tsx index 94c5df41..1b80b186 100644 --- a/src/components/manga/ChapterList.tsx +++ b/src/components/manga/ChapterList.tsx @@ -6,11 +6,12 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import { Button, CircularProgress, Stack, styled } from '@mui/material'; +import { CircularProgress, Stack, styled, Tooltip } from '@mui/material'; import Typography from '@mui/material/Typography'; import React, { ComponentProps, useMemo, useState } from 'react'; import { Virtuoso } from 'react-virtuoso'; import { useTranslation } from 'react-i18next'; +import Checkbox from '@mui/material/Checkbox'; import { TChapter, TManga, TranslationKey } from '@/typings'; import { requestManager } from '@/lib/requests/RequestManager.ts'; import { ChapterCard } from '@/components/manga/ChapterCard'; @@ -24,6 +25,16 @@ 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 ChapterListHeader = styled(Stack)(({ theme }) => ({ + margin: 8, + marginBottom: 0, + marginRight: '10px', + minHeight: 40, + [theme.breakpoints.down('md')]: { + marginRight: 0, + }, +})); + const StyledVirtuoso = styled(Virtuoso)(({ theme }) => ({ listStyle: 'none', padding: 0, @@ -97,6 +108,9 @@ export const ChapterList: React.FC = ({ manga, isRefreshing }) => { const nextChapterIndexToRead = (manga.lastReadChapter?.sourceOrder ?? 0) + 1; const isLatestChapterRead = manga.chapters.totalCount === manga.lastReadChapter?.sourceOrder; + const areAllChaptersSelected = selection?.length === chapters.length; + const areNoneChaptersSelected = !selection; + const handleSelection = (index: number) => { const chapter = visibleChapters[index]; if (!chapter) return; @@ -111,14 +125,18 @@ export const ChapterList: React.FC = ({ manga, isRefreshing }) => { } }; - const handleSelectAll = () => { - if (selection === null) return; - setSelection(visibleChapters.map((c) => c.id)); - }; - - const handleClear = () => { - if (selection === null) return; - setSelection(null); + const handleSelectAll = (event: React.ChangeEvent) => { + const selectAll = event.target.checked; + switch (selectAll) { + case true: + setSelection(visibleChapters.map((c) => c.id)); + break; + case false: + setSelection(null); + break; + default: + break; + } }; const handleFabAction: ComponentProps['onAction'] = (action, actionChapters) => { @@ -219,36 +237,27 @@ export const ChapterList: React.FC = ({ manga, isRefreshing }) => { return ( <> - + {`${visibleChapters.length} ${t('chapter.title', { count: visibleChapters.length, })}`} - {selection === null ? ( + - ) : ( - - - - - )} - + + + + + {noChaptersFound && } {noChaptersMatchingFilter && }