Skip to content

Commit

Permalink
update text review input
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleykwan committed Feb 26, 2024
1 parent 89a46cb commit cf0ebdd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 117 deletions.
145 changes: 39 additions & 106 deletions mobile/Components/LibraryCarousel/LibraryCarouselTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}?` +
Expand All @@ -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;
}

Expand Down
27 changes: 16 additions & 11 deletions mobile/Components/TextReview/TextReview.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -20,14 +20,18 @@ function TextReview(props) {
}}
>
<Text style={styles.title}>What are your thoughts on this book?</Text>
<TextInput
style={styles.reviewInput}
onChangeText={setText}
value={text}
editable
multiline
numberOfLines={4}
/>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={{flex: 1, width: "90%"}}>
<TextInput
style={styles.reviewInput}
onChangeText={setText}
value={text}
editable
multiline
numberOfLines={4}
/>
</View>
</TouchableWithoutFeedback>
<Pressable
onPress={() => navigation.navigate("navbar")}
style={styles.saveButton}
Expand All @@ -48,7 +52,6 @@ const styles = StyleSheet.create({
title: {
fontSize: 25,
marginTop: 50,
marginVertical: 20,
fontWeight: "600",
marginHorizontal: 40,
textAlign: "center",
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit cf0ebdd

Please sign in to comment.