diff --git a/frontend/BookBae/screens/HomeScreen.js b/frontend/BookBae/screens/HomeScreen.js index cb02b9a..211ff29 100644 --- a/frontend/BookBae/screens/HomeScreen.js +++ b/frontend/BookBae/screens/HomeScreen.js @@ -10,7 +10,6 @@ import { } from 'react-native'; import RadioForm from 'react-native-simple-radio-button'; import Client from '../Client.js'; -import axios from 'axios'; import {styles, matchStyles} from './HomeScreenStyles'; /** @@ -93,49 +92,26 @@ const HomeScreen = ({navigation}) => { if ('favGenre' in match) { matchInfo.favGenre = match.favGenre; } + // adds books. + if ('bookList' in match) { + let books = []; + if (match.bookList.entries.length >= 2) { + for (let j = 0; j < 2; j++) { + books[j] = match.bookList.entries[j].bookId; + } + } + matchInfo.books = books; + } // updates name to solely include first name. if (match.name.split(' ').length > 1) { matchInfo.name = match.name.split(' ')[0]; } - // handles adding books. - if ('books' in match) { - // matchInfo.books = match.books; - // add new user data to the end of the array. - let coverList = []; - for (let j = 0; j < 2 && j < match.books.length; i++) { - // try/catch block to set new book covers. - try { - // get new book. - axios - .get( - 'https://www.googleapis.com/books/v1/volumes/' + - match.books[i], - ) - .then(bookData => { - // add book to end of list. - coverList[j] = - bookData.data.volumeInfo.imageLinks.smallThumbnail; - }); - } catch (error) { - // log error if necessary - console.log(error); - } - } - matchInfo.books = coverList; - setMatches(prevState => { - prevState.push(matchInfo); - return [...prevState]; - }); - } else { - // other option must be separate to avoid missing a promise. - // add new user data to the end of the array. - setMatches(prevState => { - prevState.push(matchInfo); - return [...prevState]; - }); - } + setMatches(prevState => { + prevState.push(matchInfo); + return [...prevState]; + }); } } }); diff --git a/frontend/BookBae/screens/onboarding/EnterBooksScreen.js b/frontend/BookBae/screens/onboarding/EnterBooksScreen.js index db28036..c8a1088 100644 --- a/frontend/BookBae/screens/onboarding/EnterBooksScreen.js +++ b/frontend/BookBae/screens/onboarding/EnterBooksScreen.js @@ -7,7 +7,7 @@ import { TextInput, Pressable, FlatList, - Image + Image, } from 'react-native'; import axios from 'axios'; @@ -19,19 +19,19 @@ const EnterBooksScreen = ({route, navigation}) => { // Pass the ids of the selected books on to the next onboarding screen const onPress = () => { console.log('leave books'); - const idList = bookList.map(book => book.id); + const coverList = bookList.map(book => book.volumeInfo.imageLinks.smallThumbnail); navigation.navigate('EnterPhotoScreen', { ...route.params, - books: idList, + books: coverList, }); }; // Adds a book to the user's list - const addNewBook = (book) => { + const addNewBook = book => { setBookList(prevState => { prevState.push(book); return [...prevState]; - }) + }); }; // Displays search results; @@ -44,10 +44,8 @@ const EnterBooksScreen = ({route, navigation}) => { }); }; - return ( - Start Typing a Book Title: {/* search bar */} @@ -69,7 +67,9 @@ const EnterBooksScreen = ({route, navigation}) => { addNewBook(item)}/>} + renderItem={({item}) => ( + addNewBook(item)} /> + )} /> @@ -94,13 +94,16 @@ const EnterBooksScreen = ({route, navigation}) => { const BookListItem = ({book, onClick}) => { return ( - - - {book.volumeInfo.title} - + + + {book.volumeInfo.title} + - ) -} + ); +}; const styles = StyleSheet.create({ title: {