From 2658831e83321da1e7dc04d6a2bcfab58b51f2b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 13:45:31 +0100 Subject: [PATCH] pagination controls don't reset search --- .../pages/archivePage/archivePage.jsx | 91 +++++++++++-------- .../pages/archivePage/archivePage.less | 24 +++++ 2 files changed, 79 insertions(+), 36 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index e8ea87a98..8e2300851 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -26,26 +26,22 @@ const ArchivePage = createClass({ //request title : this.props.query.title || '', //tags : {}, - legacy : true, - v3 : true, - pageSize : 10, - page : 1, + legacy : `${this.props.query.legacy === 'false' ? false : true }`, + v3 : `${this.props.query.v3 === 'false' ? false : true }`, + pageSize : this.props.query.size || 10, + page : this.props.query.page || 1, //response brewCollection : null, totalPages : null, totalBrews : null, - searching : false, error : null, }; }, componentDidMount : function() { - - }, - handleChange(inputName, e) { - this.setState({ [inputName]: e.target.value }); + }, updateStateWithBrews : function (brews, page, totalPages, totalBrews) { @@ -58,8 +54,22 @@ const ArchivePage = createClass({ }); }, - loadPage : async function(page) { - this.updateUrl(); + updateStateWithForm : function() { + this.setState({ + title: document.getElementById( 'title' ).value || "", + pageSize: document.getElementById( 'size' ).value || 10, + v3: document.getElementById('v3').checked, + legacy: document.getElementById('legacy').checked, + }); + }, + + loadPage : async function(page, update) { + console.log(update); + if(update === true) { + this.updateStateWithForm(); + this.updateUrl(); + }; + try { this.setState({ searching: true, error: null }); @@ -75,7 +85,7 @@ const ArchivePage = createClass({ } catch (error) { console.log(`LoadPage error: ${error}`); this.setState({ error: `${error}` }); - this.updateStateWithBrews([], 1, 1); + this.updateStateWithBrews([], 1, 1, 0); } }, @@ -95,9 +105,9 @@ const ArchivePage = createClass({ }, renderPaginationControls() { - const { page, totalPages,} = this.state; + const { page, totalPages} = this.state; const pages = new Array(totalPages).fill().map((_, index) => ( -
  • this.loadPage(index+1)}>{index + 1}
  • +
  • this.loadPage(index + 1, false)}>{index + 1}
  • )); if(totalPages === null) {return;} @@ -107,14 +117,14 @@ const ArchivePage = createClass({ {page > 1 && ( )}
      {pages}
    {page < totalPages && ( - )} @@ -123,26 +133,34 @@ const ArchivePage = createClass({ }, renderFoundBrews() { - const { title, brewCollection, page, totalPages, error } = this.state; + const { title, brewCollection, page, totalPages, error, searching } = this.state; + console.log(searching === false && !brewCollection); + if(searching === false && title === '' && error === null) {return (

    Whenever you want, just start typing...

    );} - if(title === '' && error === null) {return (

    Whenever you want, just start typing...

    );} - - if(error === 'Error: Service Unavailable') { + if(searching === false && error === 'Error: Service Unavailable') { return (

    I'm sorry, your request didn't work


    Your search is not specific enough. Too many brews meet this criteria for us to display them.

    ); - } - - if(!brewCollection || brewCollection.length === 0 || error === 'Error: Not found') { + }; + + if(searching === false && (!brewCollection || error === 'Error: Not found')) { return (

    We haven't found brews meeting your request.

    ); - } + }; + + if(searching === true) { + return ( +
    +

    Searching

    ...

    +
    + ); + }; return (
    @@ -157,6 +175,9 @@ const ArchivePage = createClass({ renderForm : function () { + const v3 = (this.state.v3 === 'true'); + const legacy = (this.state.legacy === 'true'); + return (

    Brew Lookup

    @@ -164,14 +185,13 @@ const ArchivePage = createClass({