mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-18 18:42:41 +00:00
fix page size to count
This commit is contained in:
@@ -28,7 +28,7 @@ const ArchivePage = createClass({
|
|||||||
//tags: {},
|
//tags: {},
|
||||||
legacy: this.props.query.legacy !== 'false',
|
legacy: this.props.query.legacy !== 'false',
|
||||||
v3: this.props.query.v3 !== 'false',
|
v3: this.props.query.v3 !== 'false',
|
||||||
pageSize: this.props.query.size || 10,
|
count: this.props.query.count || 10,
|
||||||
page: parseInt(this.props.query.page) || 1,
|
page: parseInt(this.props.query.page) || 1,
|
||||||
|
|
||||||
//# response
|
//# response
|
||||||
@@ -57,20 +57,20 @@ const ArchivePage = createClass({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
updateUrl: function (title, page, size, v3, legacy) {
|
updateUrl: function (title, page, count, v3, legacy) {
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
const urlParams = new URLSearchParams(url.search);
|
const urlParams = new URLSearchParams(url.search);
|
||||||
|
|
||||||
//clean all params
|
//clean all params
|
||||||
urlParams.delete('title');
|
urlParams.delete('title');
|
||||||
urlParams.delete('page');
|
urlParams.delete('page');
|
||||||
urlParams.delete('size');
|
urlParams.delete('count');
|
||||||
urlParams.delete('v3');
|
urlParams.delete('v3');
|
||||||
urlParams.delete('legacy');
|
urlParams.delete('legacy');
|
||||||
|
|
||||||
urlParams.set('title', title);
|
urlParams.set('title', title);
|
||||||
urlParams.set('page', page);
|
urlParams.set('page', page);
|
||||||
urlParams.set('size', size);
|
urlParams.set('count', count);
|
||||||
urlParams.set('v3', v3);
|
urlParams.set('v3', v3);
|
||||||
urlParams.set('legacy', legacy);
|
urlParams.set('legacy', legacy);
|
||||||
|
|
||||||
@@ -81,15 +81,18 @@ const ArchivePage = createClass({
|
|||||||
loadPage: async function (page, update) {
|
loadPage: async function (page, update) {
|
||||||
console.log('running loadPage');
|
console.log('running loadPage');
|
||||||
this.setState({ searching: true, error: null });
|
this.setState({ searching: true, error: null });
|
||||||
|
console.log('props: ',this.props.query.count, '| state: ', this.state.count, '| input: ', document.getElementById('count').value || 10);
|
||||||
|
|
||||||
const performSearch = async ({ title, size, v3, legacy }) => {
|
const performSearch = async ({ title, count, v3, legacy }) => {
|
||||||
|
this.updateUrl(title, page, count, v3, legacy);
|
||||||
if (title !== '') {
|
if (title !== '') {
|
||||||
try {
|
try {
|
||||||
const response = await request.get(
|
const response = await request.get(
|
||||||
`/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}`
|
`/api/archive?title=${title}&page=${page}&count=${count}&v3=${v3}&legacy=${legacy}`
|
||||||
);
|
);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
this.updateStateWithBrews(response.body.brews, page);
|
this.updateStateWithBrews(response.body.brews, page);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Error: ${response.status}`);
|
throw new Error(`Error: ${response.status}`);
|
||||||
}
|
}
|
||||||
@@ -105,25 +108,25 @@ const ArchivePage = createClass({
|
|||||||
|
|
||||||
if (update === true) {
|
if (update === true) {
|
||||||
const title = document.getElementById('title').value || '';
|
const title = document.getElementById('title').value || '';
|
||||||
const size = document.getElementById('size').value || 10;
|
const count = document.getElementById('count').value || 10;
|
||||||
const v3 = document.getElementById('v3').checked;
|
const v3 = document.getElementById('v3').checked;
|
||||||
const legacy = document.getElementById('legacy').checked;
|
const legacy = document.getElementById('legacy').checked;
|
||||||
|
|
||||||
this.setState(
|
this.setState(
|
||||||
{
|
{
|
||||||
title: title,
|
title: title,
|
||||||
pageSize: size,
|
count: count,
|
||||||
v3: v3,
|
v3: v3,
|
||||||
legacy: legacy,
|
legacy: legacy,
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
// State is updated, now perform the search
|
// State is updated, now perform the search
|
||||||
performSearch({ title, size, v3, legacy });
|
performSearch({ title, count, v3, legacy });
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const { title, size, v3, legacy } = this.state;
|
const { title, count, v3, legacy } = this.state;
|
||||||
performSearch({ title, size, v3, legacy });
|
performSearch({ title, count, v3, legacy });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -214,7 +217,7 @@ const ArchivePage = createClass({
|
|||||||
</small>
|
</small>
|
||||||
<label>
|
<label>
|
||||||
Results per page
|
Results per page
|
||||||
<select name="pageSize" id="size">
|
<select name="count" id="count">
|
||||||
<option value="10" default>10</option>
|
<option value="10" default>10</option>
|
||||||
<option value="20">20</option>
|
<option value="20">20</option>
|
||||||
<option value="40">40</option>
|
<option value="40">40</option>
|
||||||
@@ -278,9 +281,9 @@ const ArchivePage = createClass({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size = parseInt(this.state.pageSize);
|
const count = parseInt(this.state.count);
|
||||||
const { page, totalBrews } = this.state;
|
const { page, totalBrews } = this.state;
|
||||||
const totalPages = Math.ceil(totalBrews / size);
|
const totalPages = Math.ceil(totalBrews / count);
|
||||||
|
|
||||||
let startPage, endPage;
|
let startPage, endPage;
|
||||||
if (page <= 6) {
|
if (page <= 6) {
|
||||||
|
|||||||
@@ -60,9 +60,9 @@ const archive = {
|
|||||||
|
|
||||||
const title = req.query.title || '';
|
const title = req.query.title || '';
|
||||||
const page = Math.max(parseInt(req.query.page) || 1, 1);
|
const page = Math.max(parseInt(req.query.page) || 1, 1);
|
||||||
const minPageSize = 6;
|
const mincount = 10;
|
||||||
const pageSize = Math.max(parseInt(req.query.size) || 10, minPageSize);
|
const count = Math.max(parseInt(req.query.count) || 10, mincount);
|
||||||
const skip = (page - 1) * pageSize;
|
const skip = (page - 1) * count;
|
||||||
|
|
||||||
const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3);
|
const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3);
|
||||||
const titleConditionsArray = buildTitleConditions(title);
|
const titleConditionsArray = buildTitleConditions(title);
|
||||||
@@ -79,7 +79,7 @@ const archive = {
|
|||||||
};
|
};
|
||||||
const brews = await HomebrewModel.find(titleQuery, projection)
|
const brews = await HomebrewModel.find(titleQuery, projection)
|
||||||
.skip(skip)
|
.skip(skip)
|
||||||
.limit(pageSize)
|
.limit(count)
|
||||||
.maxTimeMS(5000)
|
.maxTimeMS(5000)
|
||||||
.exec();
|
.exec();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user