0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-01 10:52:46 +00:00

fix html response

This commit is contained in:
Víctor Losada Hernández
2024-02-12 08:44:18 +01:00
parent fe449abb47
commit 71c52b4587
2 changed files with 22 additions and 18 deletions

View File

@@ -31,7 +31,7 @@ const ArchivePage = createClass({
}; };
}, },
componentDidMount : function() { componentDidMount : function() {
this.loadPage(1);
}, },
handleChange(e) { handleChange(e) {
this.setState({ title: e.target.value }); this.setState({ title: e.target.value });
@@ -45,21 +45,24 @@ const ArchivePage = createClass({
searching: false searching: false
}); });
}, },
loadPage: async function(pageNumber) { loadPage: async function(page) {
try { if(this.state.title == '') {} else {
this.updateUrl();
this.setState({ searching: true, error: null }); try {
const title = encodeURIComponent(this.state.title); //this.updateUrl();
const response = await fetch(`/archive?title=${title}&page=${pageNumber}`); this.setState({ searching: true, error: null });
const title = encodeURIComponent(this.state.title);
const response = await fetch(`/archive?title=${title}&page=${page}`);
if (response.ok) { if (response.ok) {
const res = await response.json(); const res = await response.json();
this.updateStateWithBrews(res.brews, pageNumber, res.totalPages); this.updateStateWithBrews(res.brews, page, res.totalPages);
}
} catch (error) {
console.log("LoadPage error: " + error);
} }
} catch (error) {
console.log("LoadPage error: " + error);
} }
}, },
updateUrl: function() { updateUrl: function() {

View File

@@ -7,13 +7,14 @@ const archive = {
/* Searches for matching title, also attempts to partial match */ /* Searches for matching title, also attempts to partial match */
findBrews: async (req, res, next) => { findBrews: async (req, res, next) => {
try { try {
const page = parseInt(req.params.page) || 1; const title = req.query.title || '';
const page = parseInt(req.query.page) || 1;
console.log('try:',page); console.log('try:',page);
const pageSize = 10; // Set a default page size const pageSize = 10; // Set a default page size
const skip = (page - 1) * pageSize; const skip = (page - 1) * pageSize;
const title = { const titleQuery = {
title: { $regex: decodeURIComponent(req.params.title), $options: 'i' }, title: { $regex: decodeURIComponent(title), $options: 'i' },
published: true published: true
}; };
@@ -24,7 +25,7 @@ const archive = {
textBin: 0, textBin: 0,
}; };
const brews = await HomebrewModel.find(title, projection) const brews = await HomebrewModel.find(titleQuery, projection)
.skip(skip) .skip(skip)
.limit(pageSize) .limit(pageSize)
.maxTimeMS(5000) .maxTimeMS(5000)
@@ -47,6 +48,6 @@ const archive = {
} }
}; };
router.get('/archive/:title/:page', asyncHandler(archive.findBrews)); router.get('/archive', asyncHandler(archive.findBrews));
module.exports = router; module.exports = router;