Fix library and novel item

This commit is contained in:
Rajarshee Chatterjee
2020-12-26 19:56:24 +05:30
parent ad35821c2f
commit b1917664ce
5 changed files with 62 additions and 26 deletions
+9 -4
View File
@@ -21,18 +21,23 @@ export default function App() {
const createTables = () =>
db.transaction((tx) => {
tx.executeSql(
"CREATE TABLE IF NOT EXISTS LibraryTable (novelUrl VARCHAR(255) NOT NULL PRIMARY KEY, novelName VARCHAR(255), novelCover VARCHAR(255), novelSummary TEXT, Alternative VARCHAR(255), `Author(s)` VARCHAR(255), `Genre(s)` VARCHAR(255), Type VARCHAR(255), `Release` VARCHAR(255), Status VARCHAR(255))"
"CREATE TABLE IF NOT EXISTS LibraryTable (novelUrl VARCHAR(255) PRIMARY KEY, novelName VARCHAR(255), novelCover VARCHAR(255), novelSummary TEXT, Alternative VARCHAR(255), `Author(s)` VARCHAR(255), `Genre(s)` VARCHAR(255), Type VARCHAR(255), `Release` VARCHAR(255), Status VARCHAR(255))",
null,
(tx, results) => console.log("Library Table Created"),
(tx, error) => console.log(error)
);
console.log("Library Table Created");
tx.executeSql(
"CREATE TABLE IF NOT EXISTS ChapterTable (chapterUrl VARCHAR(255), chapterName VARCHAR(255), releaseDate VARCHAR(255), novelUrl VARCHAR(255), FOREIGN KEY (novelUrl) REFERENCES LibraryTable(novelUrl) ON DELETE CASCADE)"
"CREATE TABLE IF NOT EXISTS ChapterTable (chapterId INTEGER PRIMARY KEY AUTOINCREMENT, chapterUrl VARCHAR(255), chapterName VARCHAR(255), releaseDate VARCHAR(255), novelUrl VARCHAR(255), FOREIGN KEY (novelUrl) REFERENCES LibraryTable(novelUrl) ON DELETE CASCADE)",
null,
(tx, results) => console.log("Chapter Table Created"),
(tx, error) => console.log(error)
);
});
useEffect(() => {
createTables();
});
}, []);
if (fontsLoaded) {
return (
+5 -5
View File
@@ -6,7 +6,7 @@ import { TransitionPresets } from "@react-navigation/stack";
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
import Library from "../screens/Library";
import Updates from "../screens/Updates";
import Browse from "../screens/Browse";
import Latest from "../screens/Latest";
import More from "../screens/More";
import Search from "../screens/Search";
@@ -59,12 +59,12 @@ const SearchStack = () => {
);
};
const UpdatesStack = () => {
const BrowseStack = () => {
return (
<Stack.Navigator>
<Stack.Screen
name="Browse"
component={Updates}
component={Browse}
options={{ headerShown: false }}
/>
</Stack.Navigator>
@@ -91,7 +91,7 @@ const Router = () => {
activeColor="#3399FF"
>
<Tab.Screen
name="All Novels"
name="My Library"
component={LibraryStack}
options={{
tabBarIcon: ({ color }) => (
@@ -132,7 +132,7 @@ const Router = () => {
/>
<Tab.Screen
name="Browse"
component={UpdatesStack}
component={BrowseStack}
options={{
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons
@@ -63,7 +63,7 @@ const AllNovels = ({ navigation }) => {
<Provider>
<Appbar.Header style={{ backgroundColor: theme.colorDarkPrimary }}>
<Appbar.Content
title="All Novels"
title="Browse"
titleStyle={{ color: theme.textColorPrimaryDark }}
/>
<Appbar.Action
+12 -4
View File
@@ -44,7 +44,15 @@ const UpdatesScreen = ({ navigation }) => {
"DROP TABLE LibraryTable",
null,
(txObj, { rows: { _array } }) => {
console.log("DELETED TABLE");
console.log("DELETED LIB TABLE");
},
(txObj, error) => console.log("Error ", error)
);
tx.executeSql(
"DROP TABLE ChapterTable",
null,
(txObj, { rows: { _array } }) => {
console.log("DELETED CHAP TABLE");
},
(txObj, error) => console.log("Error ", error)
);
@@ -136,11 +144,11 @@ const UpdatesScreen = ({ navigation }) => {
}
/>
)}
<Button mode="contained" onPress={() => deleted()}>
Delete Library Table
</Button>
</>
)}
{/* <Button mode="contained" onPress={() => deleted()}>
Delete Library Table
</Button> */}
</View>
);
};
+35 -12
View File
@@ -8,6 +8,7 @@ import {
FlatList,
ScrollView,
RefreshControl,
ToastAndroid,
} from "react-native";
import {
Appbar,
@@ -33,7 +34,7 @@ const NovelItem = ({ route, navigation }) => {
const [more, setMore] = useState(false);
const [libraryStatus, setlibraryStatus] = useState();
// const [dbFlag, setDbFlag] = useState(0);
const [sort, setSort] = useState("DESC");
const getNovel = () => {
fetch(`http://192.168.1.39:5000/api/novel/${item.novelUrl}`)
@@ -76,6 +77,26 @@ const NovelItem = ({ route, navigation }) => {
});
};
// const sortChapters = () => {
// setRefreshing(true);
// if (libraryStatus === 0) {
// setChapters((chapters) => chapters.reverse());
// } else {
// db.transaction((tx) => {
// tx.executeSql(
// `SELECT * FROM ChapterTable WHERE novelUrl=? ORDER BY chapterId ${sort}`,
// [item.novelUrl],
// (txObj, { rows: { _array } }) => {
// setChapters(_array);
// sort === "ASC" ? setSort("DESC") : setSort("ASC");
// setRefreshing(false);
// },
// (txObj, error) => console.log("Error ", error)
// );
// });
// }
// };
const insertToLibrary = () => {
if (libraryStatus === 0) {
db.transaction((tx) => {
@@ -93,7 +114,11 @@ const NovelItem = ({ route, navigation }) => {
novel.Release,
novel.Status,
],
(tx, res) => console.log("Inserted Novel"),
(tx, res) =>
ToastAndroid.show(
"Added to library",
ToastAndroid.SHORT
),
(txObj, error) => console.log("Error ", error)
);
@@ -116,7 +141,10 @@ const NovelItem = ({ route, navigation }) => {
"DELETE FROM LibraryTable WHERE novelUrl=?",
[item.novelUrl],
(txObj, res) => {
console.log("DELETED NOVEL FROM TABLE");
ToastAndroid.show(
"Removed from library",
ToastAndroid.SHORT
);
},
(txObj, error) => console.log("Error ", error)
);
@@ -380,9 +408,7 @@ const NovelItem = ({ route, navigation }) => {
justifyContent: "space-between",
alignItems: "center",
}}
// onPress={() =>
// setChapters((chapters) => chapters.reverse())
// }
// onPress={() => sortChapters()}
rippleColor={theme.rippleColorDark}
>
<>
@@ -400,11 +426,8 @@ const NovelItem = ({ route, navigation }) => {
icon="filter-variant"
color={theme.textColorPrimaryDark}
size={20}
// onPress={() =>
// setChapters((chapters) =>
// chapters.reverse()
// )
// }
// onPress={() => sortChapters()}
disabled
/>
</>
</TouchableRipple>
@@ -412,7 +435,7 @@ const NovelItem = ({ route, navigation }) => {
data={chapters}
extraData={chapters}
showsVerticalScrollIndicator={false}
keyExtractor={(item) => novel.chapterUrl}
keyExtractor={(item) => item.chapterId}
removeClippedSubviews={true}
maxToRenderPerBatch={10}
initialNumToRender={10}