0
0
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:
Víctor Losada Hernández
2024-02-15 01:26:54 +01:00
parent 46262c56db
commit 3427fa1e94
2 changed files with 9 additions and 6 deletions

View File

@@ -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} />
))}

View File

@@ -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' });