From e9320d11057db9a0ff5ff1588b5c274920c83c75 Mon Sep 17 00:00:00 2001 From: Elliott Zackrone <97812144+ezackr@users.noreply.github.com> Date: Wed, 1 Jun 2022 19:55:11 -0700 Subject: [PATCH 1/2] fixed covers to load immediately and not lag behind other profile information --- frontend/BookBae/screens/HomeScreen.js | 57 +++++++------------ .../screens/onboarding/EnterBooksScreen.js | 31 +++++----- 2 files changed, 36 insertions(+), 52 deletions(-) diff --git a/frontend/BookBae/screens/HomeScreen.js b/frontend/BookBae/screens/HomeScreen.js index cb02b9a..9f58d45 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,31 @@ const HomeScreen = ({navigation}) => { if ('favGenre' in match) { matchInfo.favGenre = match.favGenre; } + // adds books. + if ('bookList' in match) { + console.log(match.bookList.entries); + /* + let coverList = match.bookList.entries; + let books = []; + if (coverList.length >= 2) { + for (let j = 0; j < 2; j++) { + books[j] = coverList[j].bookId; + } + } + matchInfo.books = books; + */ + } // updates name to solely include first name. if (match.name.split(' ').length > 1) { matchInfo.name = match.name.split(' ')[0]; } + console.log(match); - // 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: { From 76a7b627f9098670ffc07929d2ca13129b44e500 Mon Sep 17 00:00:00 2001 From: Elliott Zackrone <97812144+ezackr@users.noreply.github.com> Date: Wed, 1 Jun 2022 20:11:08 -0700 Subject: [PATCH 2/2] all of the titles are dynamically rendered --- frontend/BookBae/screens/HomeScreen.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/frontend/BookBae/screens/HomeScreen.js b/frontend/BookBae/screens/HomeScreen.js index 9f58d45..211ff29 100644 --- a/frontend/BookBae/screens/HomeScreen.js +++ b/frontend/BookBae/screens/HomeScreen.js @@ -94,24 +94,19 @@ const HomeScreen = ({navigation}) => { } // adds books. if ('bookList' in match) { - console.log(match.bookList.entries); - /* - let coverList = match.bookList.entries; let books = []; - if (coverList.length >= 2) { + if (match.bookList.entries.length >= 2) { for (let j = 0; j < 2; j++) { - books[j] = coverList[j].bookId; + 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]; } - console.log(match); setMatches(prevState => { prevState.push(matchInfo);