diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 3fc85c162..f82488af3 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -26,6 +26,7 @@ const ArchivePage = createClass({ brewCollection : null, page : 1, totalPages : 1, + totalBrews : 0, searching : false, error : null, }; @@ -37,11 +38,12 @@ const ArchivePage = createClass({ this.setState({ title: e.target.value }); }, - updateStateWithBrews : function (brews, page, totalPages) { + updateStateWithBrews : function (brews, page, totalPages, totalBrews) { this.setState({ brewCollection : brews || null, page : page || 1, totalPages : totalPages || 1, + totalBrews : totalBrews, searching : false }); }, @@ -54,7 +56,7 @@ const ArchivePage = createClass({ await request.get(`/api/archive?title=${title}&page=${page}`) .then((response)=>{ if(response.ok) { - this.updateStateWithBrews(response.body.brews, page, response.body.totalPages); + this.updateStateWithBrews(response.body.brews, page, response.body.totalPages, response.body.totalBrews); } }); } catch (error) { @@ -125,6 +127,7 @@ const ArchivePage = createClass({ return (
+ Brews found: {this.state.totalBrews} {brewCollection.map((brew, index)=>( ))} diff --git a/server/archive.api.js b/server/archive.api.js index fe3d9609c..2e2ecb711 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -34,12 +34,12 @@ const archive = { // No published documents found with the given title return res.status(404).json({ error: 'Published documents not found' }); } - const totalDocuments = await HomebrewModel.countDocuments(titleQuery, projection); + const totalBrews = await HomebrewModel.countDocuments(titleQuery, projection); - const totalPages = Math.ceil(totalDocuments / pageSize); - console.log('Total brews: ', totalDocuments); + const totalPages = Math.ceil(totalBrews / pageSize); + console.log('Total brews: ', totalBrews); console.log('Total pages: ', totalPages); - return res.json({ brews, page, totalPages }); + return res.json({ brews, page, totalPages, totalBrews}); } catch (error) { console.error(error); return res.status(500).json({ error: 'Internal Server Error' });