diff --git a/mobile/Constants/ID.ts b/mobile/Constants/ID.ts
new file mode 100644
index 00000000..cc2e2efb
--- /dev/null
+++ b/mobile/Constants/ID.ts
@@ -0,0 +1,7 @@
+export default {
+ mainDBID: "65ce2a55036051cbf5fb",
+ bookCollectionID: "65ce2a5a8bea7335ef01",
+ authorCollectionID: "65ce2aa3affa7165ee7b",
+ editionCollectionID: "65ce394edd6d6603ac1e",
+ bookStatusCollectionID: "65da112a731dfc9bc51f",
+}
\ No newline at end of file
diff --git a/mobile/Screens/ProfileScreen.tsx b/mobile/Screens/ProfileScreen.tsx
index d3ad5eb3..d18a63b8 100644
--- a/mobile/Screens/ProfileScreen.tsx
+++ b/mobile/Screens/ProfileScreen.tsx
@@ -1,20 +1,132 @@
-import React, { useState } from "react";
+import React, { useEffect, useState } from "react";
import BookInfoModal from "../Components/BookInfoModal";
import {
View,
Text,
SafeAreaView,
Button,
+ StyleSheet,
Pressable,
TouchableOpacity,
} from "react-native";
+import { Query } from "appwrite";
+import { client } from "../appwrite";
+import { Databases, Account } from "appwrite";
import Colors from "../Constants/Colors";
+import ID from "../Constants/ID";
import { BookInfoContext, NavigationContext } from "../Contexts";
+const databases = new Databases(client);
export const Profile = (props) => {
+ // const user_id = request.nextUrl.searchParams.get("user_id");
+ // const user_id = account.get();
const { navigation } = props;
+ const account = new Account(client);
+ const user_id = account.get();
const [isBookInfoModalVisible, setIsBookInfoModalVisible] = useState(false);
+ const promise = databases.listDocuments(
+ ID.mainDBID,
+ ID.bookStatusCollectionID,
+ [Query.equal("user_id", user_id as unknown as string)],
+ );
+ const [booksReadCount, setBooksReadCount] = useState(0);
+ const [booksCurrReadingCount, setBooksCurrReadingCount] = useState(0);
+ const [booksWantToReadCount, setBooksWantToReadCount] = useState(0);
+ const [booksDidNotFinishCount, setBooksDidNotFinishCount] = useState(0);
+
+ useEffect(() => {
+ const account = new Account(client);
+ account
+ .get()
+ .then((response) => {
+ const user_id = response.$id; // user id in $id ?
+ const databases = new Databases(client);
+ const promise = databases.listDocuments(
+ ID.mainDBID,
+ ID.bookStatusCollectionID,
+ [Query.equal("user_id", user_id)],
+ );
+
+ promise.then(
+ function (response) {
+ const documents = response.documents;
+ let readCount = 0;
+ let currReadingCount = 0;
+ let wantToReadCount = 0;
+ let didNotFinishCount = 0;
+
+ documents.forEach((doc) => {
+ switch (doc.status) {
+ case "READ":
+ readCount++;
+ break;
+ case "CURRENTLY_READING":
+ currReadingCount++;
+ break;
+ case "WANT_TO_READ":
+ wantToReadCount++;
+ break;
+ case "DID_NOT_FINISH":
+ didNotFinishCount++;
+ break;
+ default:
+ break;
+ }
+ });
+ setBooksReadCount(readCount);
+ setBooksCurrReadingCount(currReadingCount);
+ setBooksWantToReadCount(wantToReadCount);
+ setBooksDidNotFinishCount(didNotFinishCount);
+ },
+ function (error) {
+ console.log(error);
+ },
+ );
+ })
+ .catch((error) => {
+ console.error("Error fetching user ID:", error);
+ });
+ }, []);
+
+ // promise.then(
+ // function (response) {
+ // // console.log(response); // Success
+ // const documents = response.documents;
+ // let readCount = 0;
+ // let currReadingCount = 0;
+ // let wantToReadCount = 0;
+ // let didNotFinishCount = 0;
+ // console.log(documents);
+
+ // documents.forEach((doc) => {
+ // switch (doc.status) {
+ // case "READ":
+ // readCount++;
+ // break;
+ // case "CURRENTLY_READING":
+ // currReadingCount++;
+ // break;
+ // case "WANT_TO_READ":
+ // wantToReadCount++;
+ // break;
+ // case "DID_NOT_FINISH":
+ // didNotFinishCount++;
+ // break;
+ // default:
+ // break;
+ // }
+ // });
+ // setBooksReadCount(readCount);
+ // setBooksCurrReadingCount(currReadingCount);
+ // setBooksWantToReadCount(wantToReadCount);
+ // setBooksDidNotFinishCount(didNotFinishCount);
+ // },
+ // function (error) {
+ // console.log(error); // Failure
+ // },
+ // );
+
const bookInfo = {
coverImage: "",
title: "The Poppy War",
@@ -25,26 +137,44 @@ export const Profile = (props) => {
// Function to toggle the visibility of the modal
const toggleBookInfoModal = () => {
setIsBookInfoModalVisible(!isBookInfoModalVisible);
- navigation.navigate("bookInfoModal", { bookInfo: bookInfo});
+ navigation.navigate("bookInfoModal", { bookInfo: bookInfo });
};
return (
-
-
- Profile!
-
- Testing Book Info
-
-
-
+ //
+
+ Profile
+ Books read: {booksReadCount}
+
+ Books currently reading: {booksCurrReadingCount}
+
+
+ Books want to read: {booksWantToReadCount}
+
+
+ Books did not finish: {booksDidNotFinishCount}
+
+
+ Book Info
+
+
+ //
);
};
+
+const styles = StyleSheet.create({
+ text: {
+ fontSize: 20,
+ margin: 30,
+ },
+});
diff --git a/mobile/Screens/SignIn.tsx b/mobile/Screens/SignIn.tsx
index 07456e6f..3420daf3 100644
--- a/mobile/Screens/SignIn.tsx
+++ b/mobile/Screens/SignIn.tsx
@@ -57,7 +57,6 @@ export const SignIn = (props) => {
}),
);
// if sign-in successful, nav to next screen
- // navigation.navigate('screen');
navigation.navigate("navbar");
};