0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-22 03:07:51 +00:00

change renderPagination order of operations and fix pagination not loading properly

This commit is contained in:
Víctor Losada Hernández
2024-05-21 11:57:48 +02:00
parent 21244fba58
commit f9d19c75b2

View File

@@ -99,7 +99,9 @@ const ArchivePage = createClass({
if (title !== '') {
try {
this.setState({ searching: true, error: null });
const response = await request.get(`/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}`);
const response = await request.get(
`/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}`
);
if (response.ok) {
this.updateStateWithBrews(response.body.brews, page);
}
@@ -119,6 +121,9 @@ const ArchivePage = createClass({
const { title, v3, legacy } = this.state;
if (title !== '') {
this.setState({
totalBrews: null,
});
try {
await request
.get(
@@ -178,7 +183,10 @@ const ArchivePage = createClass({
placeholder="v3 Reference Document"
/>
</label>
<small>Tip! you can use <code>-</code> to negate words, and <code>"word"</code> to specify an exact string.</small>
<small>
Tip! you can use <code>-</code> to negate words, and{' '}
<code>"word"</code> to specify an exact string.
</small>
<label>
Results per page
<input
@@ -235,16 +243,21 @@ const ArchivePage = createClass({
/>
</button>
</div>
<small>Remember, you can only search brews with this tool if they are published</small>
<small>
Remember, you can only search brews with this tool if they
are published
</small>
</div>
);
},
renderPaginationControls() {
if (this.state.totalBrews) {
renderPaginationControls: function () {
if (!this.state.totalBrews) {
return null;
}
const size = parseInt(this.state.pageSize);
const { page, totalBrews } = this.state;
const totalPages = Math.ceil(totalBrews / size);
let startPage, endPage;
@@ -284,10 +297,22 @@ const ArchivePage = createClass({
</button>
)}
<ol className="pages">
{startPage > 1 && <a className="firstPage pageNumber" onClick={() => this.loadPage(1, false)}>1 ...</a>}
{startPage > 1 && (
<a
className="firstPage pageNumber"
onClick={() => this.loadPage(1, false)}
>
1 ...
</a>
)}
{pagesAroundCurrent}
{endPage < totalPages && (
<a className="lastPage pageNumber" onClick={() => this.loadPage(totalPages, false)}>... {totalPages}</a>
<a
className="lastPage pageNumber"
onClick={() => this.loadPage(totalPages, false)}
>
... {totalPages}
</a>
)}
</ol>
{page < totalPages && (
@@ -300,14 +325,10 @@ const ArchivePage = createClass({
)}
</div>
);
} else {
return null;
}
},
renderFoundBrews() {
const { title, brewCollection, error, searching } =
this.state;
const { title, brewCollection, error, searching } = this.state;
if (searching) {
return (
@@ -333,10 +354,12 @@ const ArchivePage = createClass({
errorMessage = "404 - We didn't find any brew";
break;
case '503':
errorMessage = "503 - Service Unavailable, try again later, sorry.";
errorMessage =
'503 - Service Unavailable, try again later, sorry.';
break;
case '500':
errorMessage = "500 - We don't know what happened, go ahead and contact the mods or report as a mistake.";
errorMessage =
"500 - We don't know what happened, go ahead and contact the mods or report as a mistake.";
break;
default:
errorMessage = 'An unexpected error occurred';