diff --git a/src/redux/settings/settings.reducer.js b/src/redux/settings/settings.reducer.js index aa9bc6ce..f39fe3d9 100644 --- a/src/redux/settings/settings.reducer.js +++ b/src/redux/settings/settings.reducer.js @@ -80,6 +80,7 @@ const initialState = { showBatteryAndTime: false, autoScroll: false, autoScrollInterval: 10, + onlyUpdateOngoingNovels: false, }; const settingsReducer = (state = initialState, action) => { diff --git a/src/redux/updates/updates.actions.js b/src/redux/updates/updates.actions.js index baa9d88c..b1d576c4 100644 --- a/src/redux/updates/updates.actions.js +++ b/src/redux/updates/updates.actions.js @@ -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()); }; diff --git a/src/screens/More/GeneralSettings.js b/src/screens/More/GeneralSettings.js index 8f7eb37f..37e2c37c 100644 --- a/src/screens/More/GeneralSettings.js +++ b/src/screens/More/GeneralSettings.js @@ -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} /> + + dispatch( + setAppSettings( + "onlyUpdateOngoingNovels", + !onlyUpdateOngoingNovels + ) + ) + } + theme={theme} + /> { + 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; } } });