mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-26 13:52:38 +00:00
total brews found
This commit is contained in:
@@ -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 (
|
||||
<div className='foundBrews'>
|
||||
<span className='totalBrews'>Brews found: {this.state.totalBrews}</span>
|
||||
{brewCollection.map((brew, index)=>(
|
||||
<BrewItem brew={brew} key={index} reportError={this.props.reportError} />
|
||||
))}
|
||||
|
||||
@@ -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' });
|
||||
|
||||
Reference in New Issue
Block a user