Add option to only update ongoing novels (Closes #73)
This commit is contained in:
@@ -80,6 +80,7 @@ const initialState = {
|
||||
showBatteryAndTime: false,
|
||||
autoScroll: false,
|
||||
autoScrollInterval: 10,
|
||||
onlyUpdateOngoingNovels: false,
|
||||
};
|
||||
|
||||
const settingsReducer = (state = initialState, action) => {
|
||||
|
||||
@@ -38,9 +38,10 @@ export const updateLibraryAction = () => async (dispatch, getState) => {
|
||||
|
||||
dispatch({ type: SET_LAST_UPDATE_TIME, payload: Date.now() });
|
||||
|
||||
const { downloadNewChapters = false } = getState().settingsReducer;
|
||||
const { downloadNewChapters = false, onlyUpdateOngoingNovels = false } =
|
||||
getState().settingsReducer;
|
||||
|
||||
await updateAllNovels({ downloadNewChapters });
|
||||
await updateAllNovels({ downloadNewChapters, onlyUpdateOngoingNovels });
|
||||
|
||||
dispatch(getUpdatesAction());
|
||||
};
|
||||
|
||||
@@ -22,8 +22,11 @@ const GenralSettings = ({ navigation }) => {
|
||||
(state) => state.settingsReducer
|
||||
);
|
||||
|
||||
const { updateLibraryOnLaunch = false, downloadNewChapters = false } =
|
||||
useSettings();
|
||||
const {
|
||||
updateLibraryOnLaunch = false,
|
||||
downloadNewChapters = false,
|
||||
onlyUpdateOngoingNovels = false,
|
||||
} = useSettings();
|
||||
|
||||
const { showLastUpdateTime = true } = useSelector(
|
||||
(state) => state.updatesReducer
|
||||
@@ -88,6 +91,19 @@ const GenralSettings = ({ navigation }) => {
|
||||
}
|
||||
theme={theme}
|
||||
/>
|
||||
<SwitchSetting
|
||||
label="Only update ongoing novels"
|
||||
value={onlyUpdateOngoingNovels}
|
||||
onPress={() =>
|
||||
dispatch(
|
||||
setAppSettings(
|
||||
"onlyUpdateOngoingNovels",
|
||||
!onlyUpdateOngoingNovels
|
||||
)
|
||||
)
|
||||
}
|
||||
theme={theme}
|
||||
/>
|
||||
<SwitchSetting
|
||||
label="Show last update time"
|
||||
value={showLastUpdateTime}
|
||||
|
||||
@@ -30,7 +30,7 @@ const NovelSummary = ({ summary, followed, theme }) => {
|
||||
</Text>
|
||||
<View
|
||||
style={{
|
||||
backgroundColor: `${theme.colorPrimaryDark}B4`,
|
||||
backgroundColor: `${theme.colorPrimaryDark}D1`,
|
||||
position: "absolute",
|
||||
flex: 1,
|
||||
justifyContent: "center",
|
||||
|
||||
+33
-7
@@ -121,8 +121,19 @@ export const updateNovelChapters = async (
|
||||
});
|
||||
};
|
||||
|
||||
const sleep = (time) =>
|
||||
new Promise((resolve) => setTimeout(() => resolve(), time));
|
||||
|
||||
export const updateAllNovels = async (updateSettings) => {
|
||||
const libraryNovels = await getLibrary();
|
||||
let libraryNovels = await getLibrary();
|
||||
|
||||
const { onlyUpdateOngoingNovels = false } = updateSettings;
|
||||
|
||||
if (onlyUpdateOngoingNovels) {
|
||||
libraryNovels = libraryNovels.filter(
|
||||
(item) => item.status !== "Completed"
|
||||
);
|
||||
}
|
||||
|
||||
const options = {
|
||||
taskName: "Library Update",
|
||||
@@ -143,9 +154,6 @@ export const updateAllNovels = async (updateSettings) => {
|
||||
},
|
||||
};
|
||||
|
||||
const sleep = (time) =>
|
||||
new Promise((resolve) => setTimeout(() => resolve(), time));
|
||||
|
||||
const veryIntensiveTask = async (taskData) =>
|
||||
await new Promise(async (resolve) => {
|
||||
for (
|
||||
@@ -155,13 +163,19 @@ export const updateAllNovels = async (updateSettings) => {
|
||||
) {
|
||||
try {
|
||||
if (BackgroundService.isRunning()) {
|
||||
/**
|
||||
* Update chapters
|
||||
*/
|
||||
await updateNovelChapters(
|
||||
libraryNovels[i].sourceId,
|
||||
libraryNovels[i].novelUrl,
|
||||
libraryNovels[i].novelId,
|
||||
updateSettings
|
||||
);
|
||||
// console.log(libraryNovels[i].novelName + " Updated");
|
||||
|
||||
/**
|
||||
* Update notification
|
||||
*/
|
||||
await BackgroundService.updateNotification({
|
||||
taskTitle: libraryNovels[i].novelName,
|
||||
taskDesc:
|
||||
@@ -175,6 +189,10 @@ export const updateAllNovels = async (updateSettings) => {
|
||||
value: i + 1,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* When updating library is finished
|
||||
*/
|
||||
if (libraryNovels.length === i + 1) {
|
||||
resolve();
|
||||
|
||||
@@ -189,13 +207,21 @@ export const updateAllNovels = async (updateSettings) => {
|
||||
});
|
||||
}
|
||||
|
||||
await sleep(taskData.delay);
|
||||
const nextNovelIndex = i + 1;
|
||||
|
||||
if (
|
||||
nextNovelIndex in libraryNovels &&
|
||||
libraryNovels[nextNovelIndex].sourceId ===
|
||||
libraryNovels[i].sourceId
|
||||
) {
|
||||
await sleep(taskData.delay);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
showToast(
|
||||
libraryNovels[i].novelName + ": " + error.message
|
||||
);
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user