Fix library filters and minor fixes

This commit is contained in:
Rajarshee Chatterjee
2021-05-14 21:00:55 +05:30
parent 67096eb1ff
commit fda59f825f
8 changed files with 57 additions and 20 deletions
+1 -1
View File
@@ -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",
+12 -2
View File
@@ -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 && (
<ProgressBar color={theme.colorAccent} progress={progress} />
)}
<FlatList
contentContainerStyle={{
flexGrow: 1,
+1 -1
View File
@@ -110,7 +110,7 @@ const GlobalSearch = ({ navigation, route }) => {
title={novelName}
onBackAction={() => navigation.goBack()}
/>
{progress < 1 && (
{progress < 1 && pinned && (
<ProgressBar color={theme.colorAccent} progress={progress} />
)}
<FlatList
+11
View File
@@ -8,6 +8,7 @@ import EmptyView from "../../Components/EmptyView";
import { Searchbar } from "../../Components/Searchbar";
import { useTheme, useLibrary } from "../../Hooks/reduxHooks";
import NovelList from "../../Components/NovelList";
import { showToast } from "../../Hooks/showToast";
const Extension = ({ navigation, route }) => {
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);
});
};
+1 -3
View File
@@ -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 = () => {
+20 -10
View File
@@ -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.");
};
+10 -2
View File
@@ -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,
});
}
+1 -1
View File
@@ -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({