function searchBar(e){
    e.preventDefault();
    works = []
    if(e.target.id === 'search-center') var userSearch = document.getElementById("search-bar").value
    if(e.target.id === 'search-side') var userSearch = document.getElementById("search-input").value
    document.getElementById("sidebar-aside").style.display = "none";
    document.getElementById("title-list").style.display = "none";
    document.getElementById("search-center").style.display = "none";
    
    fetch('https://reststop.randomhouse.com/resources/works?start=0&max=20&expandLevel=1&search=' + encodeURIComponent(userSearch.trim()), {
        headers: {
            'Accept': 'application/json'}
    })
    .then(res => res.json())
    .then(async data => {
        works = data.work
        
        const response = await fetch('/api/works', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                works: works
            })
        })
        const success = await response.json()
        id = []
        for(var key in success) {
            if(success.hasOwnProperty(key)){
                id = success[key]
            }
        }
        id.forEach((ev)=>{
            console.log(ev)
        })
        return success
    })
    .then(() => {
        document.getElementById("go-top").style.display = "block";
        document.getElementById("sidebar-aside").style.display = "flex";
        document.getElementById("title-list").style.display = "flex";
        document.getElementsByTagName("html")[0].style['overflow-y'] = "scroll";
        
        printResults()
        printSidebar()
        handleFavorites()
    })
}
/**Nested fetch, gets the results of the user search from the API
 * Posts the results to the server
 * Server searches for matches and returns works that are already favorited
 * Posts all works and fills the favourite button if a book is already in the favorites list
 */
Nested fetch, gets the results of the user search from the API
Posts the results to the server
Server searches for matches and returns works that are already favorited
Posts all works and fills the favourite button if a book is already in the favorites list
Nested fetch gets the results of the user search from the API Posts the results to the server Server searches for matches and returns works that are already favorited Posts all works and fills the favourite button if a book is already in the favorites list
function searchBar(e){
    e.preventDefault();
    works = []
    if(e.target.id === 'search-center') var userSearch = document.getElementById("search-bar").value
    if(e.target.id === 'search-side') var userSearch = document.getElementById("search-input").value
    document.getElementById("sidebar-aside").style.display = "none";
    document.getElementById("title-list").style.display = "none";
    document.getElementById("search-center").style.display = "none";
    fetch('https://reststop.randomhouse.com/resources/works?start=0&max=20&expandLevel=1&search=' + encodeURIComponent(userSearch.trim()), {
        headers: {
            'Accept': 'application/json'}
    })
    .then(res => res.json())
    .then(async data => {
        works = data.work
        const response = await fetch('/api/works', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                works: works
            })
        })
        const success = await response.json()
        id = []
        for(var key in success) {
            if(success.hasOwnProperty(key)){
                id = success[key]
            }
        }
        id.forEach((ev)=>{
            console.log(ev)
        })
        return success
    })
    .then(() => {
        document.getElementById("go-top").style.display = "block";
        document.getElementById("sidebar-aside").style.display = "flex";
        document.getElementById("title-list").style.display = "flex";
        document.getElementsByTagName("html")[0].style['overflow-y'] = "scroll";
        printResults()
        printSidebar()
        handleFavorites()
    })
}
function searchBar ( e ) { e . preventDefault ( ) ; works = [ ] if ( e . target . id === 'search-center' ) var userSearch = document . getElementById ( "search-bar" ) . value if ( e . target . id === 'search-side' ) var userSearch = document . getElementById ( "search-input" ) . value document . getElementById ( "sidebar-aside" ) . style . display = "none" ; document . getElementById ( "title-list" ) . style . display = "none" ; document . getElementById ( "search-center" ) . style . display = "none" ; fetch ( 'https://reststop.randomhouse.com/resources/works?start=0&max=20&expandLevel=1&search=' + encodeURIComponent ( userSearch . trim ( ) ) , { headers : { 'Accept' : 'application/json' } } ) . then ( res => res . json ( ) ) . then ( async data => { works = data . work const response = await fetch ( '/api/works' , { method : 'POST' , headers : { 'Content-Type' : 'application/json' } , body : JSON . stringify ( { works : works } ) } ) const success = await response . json ( ) id = [ ] for ( var key in success ) { if ( success . hasOwnProperty ( key ) ) { id = success [ key ] } } id . forEach ( ( ev ) => { console . log ( ev ) } ) return success } ) . then ( ( ) => { document . getElementById ( "go-top" ) . style . display = "block" ; document . getElementById ( "sidebar-aside" ) . style . display = "flex" ; document . getElementById ( "title-list" ) . style . display = "flex" ; document . getElementsByTagName ( "html" ) [ 0 ] . style [ 'overflow-y' ] = "scroll" ; printResults ( ) printSidebar ( ) handleFavorites ( ) } ) }
Nested fetch, gets the results of the user search from the API
 Posts the results to the server
 Server searches for matches and returns works that are already favorited
 Posts all works and fills the favourite button if a book is already in the favorites list
Nested fetch gets the results of the user search from the API Posts the results to the server Server searches for matches and returns works that are already favorited Posts all works and fills the favourite button if a book is already in the favorites list