From e888c989e939b122184a2be3b10a9d818bb892df Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Tue, 20 May 2025 23:26:45 +0200 Subject: [PATCH] Fix chapter list selection with active filters The selection always used the whole chapter list regardless of the active filters, which potentially caused hidden chapters from getting selected --- src/modules/chapter/components/ChapterList.tsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/modules/chapter/components/ChapterList.tsx b/src/modules/chapter/components/ChapterList.tsx index 71f142a8..a7b602a9 100644 --- a/src/modules/chapter/components/ChapterList.tsx +++ b/src/modules/chapter/components/ChapterList.tsx @@ -138,18 +138,17 @@ export const ChapterList = ({ ); const chapters = useMemo(() => chaptersData?.chapters.nodes ?? [], [chaptersData?.chapters.nodes]); - const chapterIds = useMemo(() => chapters.map((chapter) => chapter.id), [chapters]); - - const { areNoItemsSelected, areAllItemsSelected, selectedItemIds, handleSelectAll, handleSelection } = - useSelectableCollection(chapters.length, { itemIds: chapterIds, currentKey: 'default' }); - const visibleChapters = useMemo(() => filterAndSortChapters(chapters, options), [chapters, options]); + const visibleChapterIds = useMemo(() => Chapters.getIds(visibleChapters), [visibleChapters]); const areAllChaptersRead = Mangas.isFullyRead(manga); const areAllChaptersDownloaded = Mangas.isFullyDownloaded(manga); const noChaptersFound = chapters.length === 0; const noChaptersMatchingFilter = !noChaptersFound && visibleChapters.length === 0; + const { areNoItemsSelected, areAllItemsSelected, selectedItemIds, handleSelectAll, handleSelection } = + useSelectableCollection(visibleChapterIds.length, { itemIds: visibleChapterIds, currentKey: 'default' }); + const onSelect = useCallback( (id: number, selected: boolean, selectRange?: boolean) => handleSelection(id, selected, { selectRange }), [handleSelection], @@ -235,9 +234,7 @@ export const ChapterList = ({ - handleSelectAll(checked, checked ? chapters.map((chapter) => chapter.id) : []) - } + onChange={(checked) => handleSelectAll(checked, checked ? visibleChapterIds : [])} />