mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 18:32:40 +00:00
total brews found
This commit is contained in:
@@ -26,6 +26,7 @@ const ArchivePage = createClass({
|
|||||||
brewCollection : null,
|
brewCollection : null,
|
||||||
page : 1,
|
page : 1,
|
||||||
totalPages : 1,
|
totalPages : 1,
|
||||||
|
totalBrews : 0,
|
||||||
searching : false,
|
searching : false,
|
||||||
error : null,
|
error : null,
|
||||||
};
|
};
|
||||||
@@ -37,11 +38,12 @@ const ArchivePage = createClass({
|
|||||||
this.setState({ title: e.target.value });
|
this.setState({ title: e.target.value });
|
||||||
},
|
},
|
||||||
|
|
||||||
updateStateWithBrews : function (brews, page, totalPages) {
|
updateStateWithBrews : function (brews, page, totalPages, totalBrews) {
|
||||||
this.setState({
|
this.setState({
|
||||||
brewCollection : brews || null,
|
brewCollection : brews || null,
|
||||||
page : page || 1,
|
page : page || 1,
|
||||||
totalPages : totalPages || 1,
|
totalPages : totalPages || 1,
|
||||||
|
totalBrews : totalBrews,
|
||||||
searching : false
|
searching : false
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -54,7 +56,7 @@ const ArchivePage = createClass({
|
|||||||
await request.get(`/api/archive?title=${title}&page=${page}`)
|
await request.get(`/api/archive?title=${title}&page=${page}`)
|
||||||
.then((response)=>{
|
.then((response)=>{
|
||||||
if(response.ok) {
|
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) {
|
} catch (error) {
|
||||||
@@ -125,6 +127,7 @@ const ArchivePage = createClass({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='foundBrews'>
|
<div className='foundBrews'>
|
||||||
|
<span className='totalBrews'>Brews found: {this.state.totalBrews}</span>
|
||||||
{brewCollection.map((brew, index)=>(
|
{brewCollection.map((brew, index)=>(
|
||||||
<BrewItem brew={brew} key={index} reportError={this.props.reportError} />
|
<BrewItem brew={brew} key={index} reportError={this.props.reportError} />
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -34,12 +34,12 @@ const archive = {
|
|||||||
// No published documents found with the given title
|
// No published documents found with the given title
|
||||||
return res.status(404).json({ error: 'Published documents not found' });
|
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);
|
const totalPages = Math.ceil(totalBrews / pageSize);
|
||||||
console.log('Total brews: ', totalDocuments);
|
console.log('Total brews: ', totalBrews);
|
||||||
console.log('Total pages: ', totalPages);
|
console.log('Total pages: ', totalPages);
|
||||||
return res.json({ brews, page, totalPages });
|
return res.json({ brews, page, totalPages, totalBrews});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return res.status(500).json({ error: 'Internal Server Error' });
|
return res.status(500).json({ error: 'Internal Server Error' });
|
||||||
|
|||||||
Reference in New Issue
Block a user