diff --git a/app.json b/app.json index 43ed9f97..8ba34136 100644 --- a/app.json +++ b/app.json @@ -4,7 +4,7 @@ "slug": "LNReader", "scheme": "lnreader", "version": "1.0.16", - "orientation": "portrait", + "orientation": "default", "icon": "./assets/icon.png", "splash": { "image": "./assets/splash.png", diff --git a/src/Screens/Browse/GlobalSearch.js b/src/Screens/Browse/GlobalSearch.js index 6609ee8d..63added4 100644 --- a/src/Screens/Browse/GlobalSearch.js +++ b/src/Screens/Browse/GlobalSearch.js @@ -14,6 +14,8 @@ import NovelCover from "../../Components/NovelCover"; import NovelList from "../../Components/NovelList"; import EmptyView from "../../Components/EmptyView"; import GlobalSearchNovelList from "./components/GlobalSearchNovelList"; +import { ProgressBar } from "react-native-paper"; +import { showToast } from "../../Hooks/showToast"; const GlobalSearch = ({ navigation }) => { const theme = useTheme(); @@ -22,6 +24,7 @@ const GlobalSearch = ({ navigation }) => { const [searchText, setSearchText] = useState(""); const [searchResults, setSearchResults] = useState(""); const { sources, pinned } = useSelector((state) => state.sourceReducer); + const [progress, setProgress] = useState(0); const library = useLibrary(); @@ -75,7 +78,12 @@ const GlobalSearch = ({ navigation }) => { }, ]); setLoading(false); - }); + }) + .finally(() => + setProgress( + (progress) => progress + 1 / pinnedSources.length + ) + ); }, 1000 * index) ); }; @@ -116,7 +124,9 @@ const GlobalSearch = ({ navigation }) => { onSubmitEditing={onSubmitEditing} clearSearchbar={clearSearchbar} /> - + {progress < 1 && progress > 0 && pinned && ( + + )} { title={novelName} onBackAction={() => navigation.goBack()} /> - {progress < 1 && ( + {progress < 1 && pinned && ( )} { const { sourceId, sourceName, sourceUrl } = route.params; @@ -42,6 +43,11 @@ const Extension = ({ navigation, route }) => { .then((json) => { setNovels(json); setLoading(false); + }) + .catch((error) => { + setNovels([]); + setLoading(false); + showToast(error.message); }); }; @@ -58,6 +64,11 @@ const Extension = ({ navigation, route }) => { .then((json) => { setNovels(json); setLoading(false); + }) + .catch((error) => { + setNovels([]); + setLoading(false); + showToast(error.message); }); }; diff --git a/src/Screens/Library/Library.js b/src/Screens/Library/Library.js index 2bfbd03d..4058ed6b 100644 --- a/src/Screens/Library/Library.js +++ b/src/Screens/Library/Library.js @@ -36,8 +36,6 @@ const LibraryScreen = ({ navigation }) => { filters: { sort, filter }, } = useSelector((state) => state.libraryReducer); - console.log("1.", sort, filter); - const [refreshing, setRefreshing] = useState(false); const [searchText, setSearchText] = useState(""); @@ -45,7 +43,7 @@ const LibraryScreen = ({ navigation }) => { useCallback(() => { setSearchText(""); dispatch(getLibraryAction(sort, filter)); - }, [getLibraryAction]) + }, [getLibraryAction, sort, filter]) ); const onRefresh = () => { diff --git a/src/Services/backup.js b/src/Services/backup.js index d73b0bce..cb259d8f 100644 --- a/src/Services/backup.js +++ b/src/Services/backup.js @@ -20,7 +20,8 @@ Notifications.setNotificationHandler({ export const createBackup = async () => { const novels = await getLibrary(); - const permissions = await StorageAccessFramework.requestDirectoryPermissionsAsync(); + const permissions = + await StorageAccessFramework.requestDirectoryPermissionsAsync(); if (!permissions.granted) { return; @@ -47,20 +48,29 @@ export const createBackup = async () => { export const restoreBackup = async () => { const backup = await DocumentPicker.getDocumentAsync(); + Notifications.scheduleNotificationAsync({ + content: { title: "Restoring backup" }, + trigger: null, + }); + if (backup.uri) { let novels = await StorageAccessFramework.readAsStringAsync(backup.uri); novels = await JSON.parse(novels); novels.map((novel, index) => { - restoreLibrary(novel); - if (index + 1 === novels.length) { - Notifications.scheduleNotificationAsync({ - content: { title: "Backup restored" }, - trigger: null, - }); - } + setTimeout(async () => { + if (index + 1 === novels.length) { + Notifications.scheduleNotificationAsync({ + content: { + title: "Library Updated", + body: novels.length + " novels restored", + }, + trigger: null, + }); + } + + await restoreLibrary(novel); + }, 1000 * index); }); } - - showToast("Backup restored. Restart your app."); }; diff --git a/src/Services/updates.js b/src/Services/updates.js index c8d466e6..7fb56ddb 100644 --- a/src/Services/updates.js +++ b/src/Services/updates.js @@ -113,6 +113,12 @@ export const updateNovelChapters = async (extensionId, novelUrl, novelId) => { export const updateAllNovels = async () => { const libraryNovels = await getLibrary(); + Notifications.scheduleNotificationAsync({ + identifier: "updatingNotif", + content: { title: "Updating library" }, + trigger: null, + }); + libraryNovels.map((novel, index) => setTimeout(async () => { await updateNovelChapters( @@ -120,12 +126,14 @@ export const updateAllNovels = async () => { novel.novelUrl, novel.novelId ); - console.log(novel.novelName + " Updated"); if (index + 1 === libraryNovels.length) { Notifications.scheduleNotificationAsync({ - content: { title: "Library Updated" }, + content: { + title: "Library Updated", + body: libraryNovels.length + " novels updated", + }, trigger: null, }); } diff --git a/src/redux/library/library.actions.js b/src/redux/library/library.actions.js index f96c24c2..55fc97f2 100644 --- a/src/redux/library/library.actions.js +++ b/src/redux/library/library.actions.js @@ -11,7 +11,7 @@ import { import { restoreBackup } from "../../Services/backup"; export const getLibraryAction = (sort, filter) => async (dispatch) => { - // console.log(sort, filter); + // console.log("1.", sort, filter); const res = await getLibrary(sort, filter); dispatch({