Skip to content

Commit

Permalink
Filter Duplicates in Chapter Selection (Closes #847)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajarsheechatterjee committed Jan 4, 2024
1 parent a298ed8 commit e0e593b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
45 changes: 29 additions & 16 deletions src/screens/novel/NovelScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import { getChapterScreenRouteParams } from '../../utils/NavigationUtils';
import NovelScreenLoading from './components/LoadingAnimation/NovelScreenLoading';
import { useTrackerReducer } from '@redux/hooks';
import EpubIconButton from './components/EpubIconButton';
import { uniqBy } from 'lodash-es';

const Novel = ({ route, navigation }) => {
const item = route.params;
Expand Down Expand Up @@ -290,25 +291,37 @@ const Novel = ({ route, navigation }) => {

if (lastSelectedChapter.chapterId !== chapter.chapterId) {
if (lastSelectedChapter.chapterId > chapter.chapterId) {
setSelected(sel => [
...sel,
chapter,
...chapters.filter(
chap =>
(chap.chapterId <= chapter.chapterId ||
chap.chapterId >= lastSelectedChapter.chapterId) === false,
setSelected(sel =>
uniqBy(
[
...sel,
chapter,
...chapters.filter(
chap =>
(chap.chapterId <= chapter.chapterId ||
chap.chapterId >= lastSelectedChapter.chapterId) ===
false,
),
],
'chapterId',
),
]);
);
} else {
setSelected(sel => [
...sel,
chapter,
...chapters.filter(
chap =>
(chap.chapterId >= chapter.chapterId ||
chap.chapterId <= lastSelectedChapter.chapterId) === false,
setSelected(sel =>
uniqBy(
[
...sel,
chapter,
...chapters.filter(
chap =>
(chap.chapterId >= chapter.chapterId ||
chap.chapterId <= lastSelectedChapter.chapterId) ===
false,
),
],
'chapterId',
),
]);
);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/screens/novel/components/NovelBottomSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ const ChaptersSettingsSheet = ({
: false
}
onPress={() => {
if (filter.match('AND downloaded=0')) {
if (filter.match('AND downloaded=1')) {
filterChapters(
filter.replace(' AND downloaded=0', ' AND downloaded=1'),
filter.replace(' AND downloaded=1', ' AND downloaded=0'),
);
} else if (filter.match('AND downloaded=1')) {
filterChapters(filter.replace(' AND downloaded=1', ''));
} else if (filter.match('AND downloaded=0')) {
filterChapters(filter.replace(' AND downloaded=0', ''));
} else {
filterChapters(filter + ' AND downloaded=0');
filterChapters(filter + ' AND downloaded=1');
}
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/sources/en/NovelOnline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const popularNovels = async (page: number) => {
const NovelsOnlineScraper = {
popularNovels,
parseNovelAndChapters,
parseChapter,
// parseChapter,
searchNovels,
};

Expand Down

0 comments on commit e0e593b

Please sign in to comment.