From cf0ebdd00643f034492903227faace4afaa6ebb0 Mon Sep 17 00:00:00 2001 From: Kaley Kwan Date: Mon, 26 Feb 2024 10:28:23 -0500 Subject: [PATCH] update text review input --- .../LibraryCarousel/LibraryCarouselTabs.tsx | 145 +++++------------- mobile/Components/TextReview/TextReview.tsx | 27 ++-- 2 files changed, 55 insertions(+), 117 deletions(-) diff --git a/mobile/Components/LibraryCarousel/LibraryCarouselTabs.tsx b/mobile/Components/LibraryCarousel/LibraryCarouselTabs.tsx index 7002b8cf..06552d8f 100644 --- a/mobile/Components/LibraryCarousel/LibraryCarouselTabs.tsx +++ b/mobile/Components/LibraryCarousel/LibraryCarouselTabs.tsx @@ -88,123 +88,54 @@ let userID; user.then( function (response) { - //console.log(response); // Success userID = response.$id; - //console.log(userID); }, function (error) { console.log(error); // Failure }, ); -// async function getStatuses() { -// let res = await fetch( -// `host/api/v0/bookstatus?` + -// new URLSearchParams({ -// user_id: userID, -// }), -// ); - -// const res_json = await res.json(); -// console.log(res_json); -// return res_json.results.documents.map((bookStatus) => { -// return { -// bookID: bookStatus.book, -// status: bookStatus.status, -// }; -// }); -// } - -// async function getBooks(id) { -// let res = await fetch( -// `${BACKEND_API_BOOK_SEARCH_URL}?` + -// new URLSearchParams({ -// id: id, -// }), -// ); -// const res_json = await res.json(); -// return res_json.results.documents.map((book) => { -// return { -// id: book.$id, -// title: book.title, -// author: book.authors[0].name, -// image_url: book.editions[0].thumbnail_url, -// }; -// }); -// } - -// async function getCurrentlyReadingBooks() { -// const bookStatuses = await getStatuses(); -// console.log(bookStatuses); -// let booklist = []; - -// for(const status of bookStatuses) { -// if (status.status == "CURRENTLY_READING") { -// booklist.push(...(await getBooks(status.bookID))); -// } -// } -// return booklist; -// } const databases = new Databases(client); -const promise = databases.listDocuments( - ID.mainDBID, - ID.bookStatusCollectionID, - [Query.equal("user_id", userID as unknown as string)], -); - -let read = []; -let currReading = []; -let wantToRead = []; -let didNotFinish = []; - -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; - - documents.forEach((doc) => { - switch (doc.status) { - case "READ": - read.push(doc); - break; - case "CURRENTLY_READING": - console.log("adding book to read:" + doc.book.$id) - currReading.push(doc); - break; - case "WANT_TO_READ": - wantToRead.push(doc); - break; - case "DID_NOT_FINISH": - didNotFinish.push(doc); - break; - default: - break; - } - }); - }, - function (error) { - console.log(error); - }, - ); - }) - .catch((error) => { - console.error("Error fetching user ID:", error); - }); - function CurrentlyReadingCarousel() { const [books, setBooks] = useState([]); + console.log("right before account"); + useEffect(() => { + async function getStatuses() { + let currReadingList = []; + 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), + Query.equal("status", "CURRENTLY_READING"), + ], + ); + + promise.then( + function (response) { + const documents = response.documents; + documents.forEach((doc) => { + console.log("adding doc: " + doc.book.$id); + currReadingList.push(doc); + }); + }, + function (error) { + console.log(error); + }, + ); + }) + .catch((error) => { + console.error("Error fetching user ID:", error); + }); + return currReadingList; + } async function getBooks(id) { let res = await fetch( `${BACKEND_API_BOOK_SEARCH_URL}?` + @@ -225,11 +156,13 @@ function CurrentlyReadingCarousel() { async function getCurrentlyReadingBooks() { let booklist = []; - console.log("currReading: " + currReading) + const currReading = await getStatuses(); + console.log("currReading hello: " + currReading); for (const book of currReading) { booklist.push(...(await getBooks(book.book.$id))); } + console.log("booklist: " + booklist); return booklist; } diff --git a/mobile/Components/TextReview/TextReview.tsx b/mobile/Components/TextReview/TextReview.tsx index 977633cd..21e876a7 100644 --- a/mobile/Components/TextReview/TextReview.tsx +++ b/mobile/Components/TextReview/TextReview.tsx @@ -1,5 +1,5 @@ import * as React from "react"; -import { View, Text, Pressable, StyleSheet, TextInput } from "react-native"; +import { View, Text, Pressable, StyleSheet, TextInput, TouchableWithoutFeedback, Keyboard } from "react-native"; import Modal from "react-native-modal"; import Colors from "../../Constants/Colors"; import { useState } from "react"; @@ -20,14 +20,18 @@ function TextReview(props) { }} > What are your thoughts on this book? - + + + + + navigation.navigate("navbar")} style={styles.saveButton} @@ -48,7 +52,6 @@ const styles = StyleSheet.create({ title: { fontSize: 25, marginTop: 50, - marginVertical: 20, fontWeight: "600", marginHorizontal: 40, textAlign: "center", @@ -77,11 +80,13 @@ const styles = StyleSheet.create({ backgroundColor: Colors.BUTTON_GRAY, padding: 10, paddingHorizontal: 20, - marginBottom: 100, + marginBottom: 60, borderRadius: 10, }, reviewInput: { + height: "85%", margin: 12, + marginTop: 40, borderWidth: 1, padding: 10, },