Skip to content

Commit

Permalink
Merge branch 'LNReader:master' into novel-updates-rating
Browse files Browse the repository at this point in the history
  • Loading branch information
Batorian authored Mar 1, 2025
2 parents c6655a5 + 4e3f817 commit 82d5a4f
Show file tree
Hide file tree
Showing 22 changed files with 500 additions and 308 deletions.
9 changes: 8 additions & 1 deletion android/app/src/main/assets/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,14 @@ window.addEventListener('DOMContentLoaded', async () => {
}

if (reader.generalSettings.val.removeExtraParagraphSpacing) {
html = html.replace(/<\s*br[^>]*>/gi, '\n').replace(/\n{2,}/g, '\n\n');
html = html
.replace(/(?:&nbsp;\s*|[\u200b]\s*)+(?=<\/?p[> ])/g, '')
.replace(/<br>\s*<br>\s*(?:<br>\s*)+/g, '<br><br>') //force max 2 consecutive <br>, chaining regex
.replace(
/<br>\s*<br>(?:(?!\s*<(?:em|[iab]|strong|span)[> ])|(?<!(?:\/em|\/[iab]|\/strong|\/span)>\s*<br>\s*<br>))\s*/g,
'',
) //look-around double br. If certain tags aren't near, delete the double br.
.replace(/<br>(?:(?=\s*<\/?p[> ])|(?<=<\/?p>\s*<br>))\s*/g, '');
}
reader.chapterElement.innerHTML = html;
});
Expand Down
12 changes: 8 additions & 4 deletions src/hooks/persisted/useDownload.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { ChapterInfo, NovelInfo } from '@database/types';
import ServiceManager, { BackgroundTask } from '@services/ServiceManager';
import ServiceManager, {
BackgroundTaskMetadata,
DownloadChapterTask,
QueuedBackgroundTask,
} from '@services/ServiceManager';
import { useMemo } from 'react';
import { useMMKVObject } from 'react-native-mmkv';

export const DOWNLOAD_QUEUE = 'DOWNLOAD';
export const CHAPTER_DOWNLOADING = 'CHAPTER_DOWNLOADING';

export default function useDownload() {
const [queue] = useMMKVObject<BackgroundTask[]>(
const [queue] = useMMKVObject<QueuedBackgroundTask[]>(
ServiceManager.manager.STORE_KEY,
);
const downloadQueue = useMemo(
() => queue?.filter(t => t.name === 'DOWNLOAD_CHAPTER') || [],
() => queue?.filter(t => t.task.name === 'DOWNLOAD_CHAPTER') || [],
[queue],
);
) as { task: DownloadChapterTask; meta: BackgroundTaskMetadata }[];

const downloadChapter = (novel: NovelInfo, chapter: ChapterInfo) =>
ServiceManager.manager.addTask({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const GlobalSearchSourceResults: React.FC<{ item: GlobalSearchResult }> = ({
</View>
</>
),
[item.isLoading],
[item.isLoading, library],
);
};

Expand Down
6 changes: 5 additions & 1 deletion src/screens/library/LibraryScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ const LibraryScreen = ({ navigation }: LibraryScreenProps) => {
library[index].id !== 2 &&
ServiceManager.manager.addTask({
name: 'UPDATE_LIBRARY',
data: library[index].id,
data: {
categoryId: library[index].id,
categoryName: library[index].name,
},
}),
},
{
Expand Down Expand Up @@ -289,6 +292,7 @@ const LibraryScreen = ({ navigation }: LibraryScreenProps) => {
) : null}
<LibraryView
categoryId={route.id}
categoryName={route.name}
novels={route.novels}
selectedNovelIds={selectedNovelIds}
setSelectedNovelIds={setSelectedNovelIds}
Expand Down
7 changes: 6 additions & 1 deletion src/screens/library/components/LibraryListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ServiceManager from '@services/ServiceManager';

interface Props {
categoryId: number;
categoryName: string;
novels: LibraryNovelInfo[];
selectedNovelIds: number[];
setSelectedNovelIds: React.Dispatch<React.SetStateAction<number[]>>;
Expand All @@ -24,6 +25,7 @@ interface Props {

export const LibraryView: React.FC<Props> = ({
categoryId,
categoryName,
novels,
selectedNovelIds,
setSelectedNovelIds,
Expand Down Expand Up @@ -62,7 +64,10 @@ export const LibraryView: React.FC<Props> = ({
setRefreshing(true);
ServiceManager.manager.addTask({
name: 'UPDATE_LIBRARY',
data: categoryId,
data: {
categoryId,
categoryName,
},
});
setRefreshing(false);
};
Expand Down
24 changes: 16 additions & 8 deletions src/screens/more/TaskQueueScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { showToast } from '../../utils/showToast';
import { getString } from '@strings/translations';
import { Appbar, EmptyView } from '@components';
import { TaskQueueScreenProps } from '@navigators/types';
import ServiceManager, { BackgroundTask } from '@services/ServiceManager';
import ServiceManager, { QueuedBackgroundTask } from '@services/ServiceManager';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useMMKVObject } from 'react-native-mmkv';

const DownloadQueue = ({ navigation }: TaskQueueScreenProps) => {
const theme = useTheme();
const { bottom } = useSafeAreaInsets();
const [taskQueue] = useMMKVObject<BackgroundTask[]>(
const [taskQueue] = useMMKVObject<QueuedBackgroundTask[]>(
ServiceManager.manager.STORE_KEY,
);
const [isRunning, setIsRunning] = useState(ServiceManager.manager.isRunning);
Expand All @@ -34,6 +34,8 @@ const DownloadQueue = ({ navigation }: TaskQueueScreenProps) => {
}
}, [taskQueue]);

//TODO: there should probably be a way to cancel a specific task from this screen

return (
<>
<Appbar
Expand Down Expand Up @@ -71,15 +73,21 @@ const DownloadQueue = ({ navigation }: TaskQueueScreenProps) => {
contentContainerStyle={{ flexGrow: 1, paddingBottom: 100 }}
keyExtractor={(item, index) => 'task_' + index}
data={taskQueue || []}
renderItem={({ item, index }) => (
renderItem={({ item }) => (
<View style={{ padding: 16 }}>
<Text style={{ color: theme.onSurface }}>
{item.name} - {ServiceManager.manager.getTaskDescription(item)}
</Text>
<Text style={{ color: theme.onSurface }}>{item.meta.name}</Text>
{item.meta.progressText ? (
<Text style={{ color: theme.onSurfaceVariant }}>
{item.meta.progressText}
</Text>
) : null}
<ProgressBar
indeterminate={taskQueue && taskQueue.length > 0 && index === 0}
indeterminate={
item.meta.isRunning && item.meta.progress === undefined
}
progress={item.meta.progress}
color={theme.primary}
style={{ marginTop: 8 }}
style={{ marginTop: 8, backgroundColor: theme.surface2 }}
/>
</View>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/screens/novel/NovelScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ const Novel = ({ route, navigation }: NovelScreenProps) => {
renderItem={({ item }) => (
<ChapterItem
isDownloading={downloadQueue.some(
c => c.data.chapterId === item.id,
c => c.task.data.chapterId === item.id,
)}
isLocal={novel.isLocal}
theme={theme}
Expand Down
10 changes: 8 additions & 2 deletions src/screens/novel/components/EditInfoModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,17 @@ const EditInfoModal = ({
mode="outlined"
onChangeText={text => setNewGenre(text)}
onSubmitEditing={() => {
const newGenreTrimmed = newGenre.trim();

if (newGenreTrimmed === '') {
return;
}

setNovelInfo(prevVal => ({
...prevVal,
genres: novelInfo.genres
? `${novelInfo.genres},`
: '' + newGenre.trim(),
? `${novelInfo.genres},` + newGenreTrimmed
: newGenreTrimmed,
}));
setNewGenre('');
}}
Expand Down
2 changes: 1 addition & 1 deletion src/screens/novel/components/NovelAppbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const NovelAppbar = ({
}}
onPress={() => {
showExtraMenu(false);
setCustomNovelCover;
setCustomNovelCover();
}}
/>
</Menu>
Expand Down
14 changes: 12 additions & 2 deletions src/screens/reader/ReaderScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useCallback } from 'react';
import React, { useRef, useCallback, useState, useEffect } from 'react';
import { DrawerLayoutAndroid } from 'react-native';

import { useChapterGeneralSettings, useTheme } from '@hooks/persisted';
Expand Down Expand Up @@ -63,6 +63,11 @@ export const ChapterContent = ({
const readerSheetRef = useRef<BottomSheetModalMethods>(null);
const theme = useTheme();
const { pageReader = false, keepScreenOn } = useChapterGeneralSettings();
const [bookmarked, setBookmarked] = useState(chapter.bookmark);

useEffect(() => {
setBookmarked(chapter.bookmark);
}, [chapter]);

const {
hidden,
Expand Down Expand Up @@ -146,7 +151,12 @@ export const ChapterContent = ({
<ReaderBottomSheetV2 bottomSheetRef={readerSheetRef} />
{!hidden ? (
<>
<ReaderAppbar goBack={navigation.goBack} theme={theme} />
<ReaderAppbar
goBack={navigation.goBack}
theme={theme}
bookmarked={bookmarked}
setBookmarked={setBookmarked}
/>
<ReaderFooter
theme={theme}
nextChapter={nextChapter}
Expand Down
14 changes: 8 additions & 6 deletions src/screens/reader/components/ReaderAppbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React from 'react';
import { StatusBar, StyleSheet, View } from 'react-native';
import color from 'color';

Expand All @@ -14,12 +14,14 @@ interface ReaderAppbarProps {
goBack: () => void;
}

const ReaderAppbar = ({ goBack, theme }: ReaderAppbarProps) => {
const ReaderAppbar = ({
goBack,
theme,
bookmarked,
setBookmarked,
}: ReaderAppbarProps) => {
const { chapter, novel } = useChapterContext();
const [bookmarked, setBookmarked] = useState(chapter.bookmark);
useEffect(() => {
setBookmarked(chapter.bookmark);
}, [chapter]);

return (
<Animated.View
entering={FadeIn.duration(150)}
Expand Down
10 changes: 9 additions & 1 deletion src/screens/reader/hooks/useChapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
getChapter as getDbChapter,
getNextChapter,
getPrevChapter,
markChapterRead,
Expand Down Expand Up @@ -188,10 +189,17 @@ export default function useChapter(webViewRef: RefObject<WebView>) {
useEffect(() => {
setLoading(true);
getChapter().finally(() => setLoading(false));

if (!incognitoMode) {
insertHistory(chapter.id);
setLastRead(chapter);
getDbChapter(chapter.id).then(result => setLastRead(result));
}

return () => {
if (!incognitoMode) {
getDbChapter(chapter.id).then(result => setLastRead(result));
}
};
}, [chapter]);

const refetch = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/updates/UpdatesScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const UpdatesScreen = ({ navigation }: UpdateScreenProps) => {
e.preventDefault();

navigation.navigate('MoreStack', {
screen: 'Downloads',
screen: 'TaskQueue',
});
}
}),
Expand Down
4 changes: 2 additions & 2 deletions src/screens/updates/components/UpdateNovelCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const UpdateNovelCard: React.FC<UpdateCardProps> = ({
<ChapterItem
isLocal={false}
isDownloading={downloadQueue.some(
c => c.data.chapterId === item.id,
c => c.task.data.chapterId === item.id,
)}
isUpdateCard
novelName={chapterList[0].novelName}
Expand Down Expand Up @@ -142,7 +142,7 @@ const UpdateNovelCard: React.FC<UpdateCardProps> = ({
<ChapterItem
isLocal={false}
isDownloading={downloadQueue.some(
c => c.data.chapterId === chapterList[0].id,
c => c.task.data.chapterId === chapterList[0].id,
)}
isUpdateCard
novelName={chapterList[0].novelName}
Expand Down
Loading

0 comments on commit 82d5a4f

Please sign in to comment.