mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-15 21:22:43 +00:00
change renderPagination order of operations and fix pagination not loading properly
This commit is contained in:
@@ -99,7 +99,9 @@ const ArchivePage = createClass({
|
|||||||
if (title !== '') {
|
if (title !== '') {
|
||||||
try {
|
try {
|
||||||
this.setState({ searching: true, error: null });
|
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) {
|
if (response.ok) {
|
||||||
this.updateStateWithBrews(response.body.brews, page);
|
this.updateStateWithBrews(response.body.brews, page);
|
||||||
}
|
}
|
||||||
@@ -119,6 +121,9 @@ const ArchivePage = createClass({
|
|||||||
const { title, v3, legacy } = this.state;
|
const { title, v3, legacy } = this.state;
|
||||||
|
|
||||||
if (title !== '') {
|
if (title !== '') {
|
||||||
|
this.setState({
|
||||||
|
totalBrews: null,
|
||||||
|
});
|
||||||
try {
|
try {
|
||||||
await request
|
await request
|
||||||
.get(
|
.get(
|
||||||
@@ -178,7 +183,10 @@ const ArchivePage = createClass({
|
|||||||
placeholder="v3 Reference Document"
|
placeholder="v3 Reference Document"
|
||||||
/>
|
/>
|
||||||
</label>
|
</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>
|
<label>
|
||||||
Results per page
|
Results per page
|
||||||
<input
|
<input
|
||||||
@@ -235,16 +243,21 @@ const ArchivePage = createClass({
|
|||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
renderPaginationControls() {
|
renderPaginationControls: function () {
|
||||||
if (this.state.totalBrews) {
|
if (!this.state.totalBrews) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const size = parseInt(this.state.pageSize);
|
const size = parseInt(this.state.pageSize);
|
||||||
const { page, totalBrews } = this.state;
|
const { page, totalBrews } = this.state;
|
||||||
|
|
||||||
const totalPages = Math.ceil(totalBrews / size);
|
const totalPages = Math.ceil(totalBrews / size);
|
||||||
|
|
||||||
let startPage, endPage;
|
let startPage, endPage;
|
||||||
@@ -284,10 +297,22 @@ const ArchivePage = createClass({
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
<ol className="pages">
|
<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}
|
{pagesAroundCurrent}
|
||||||
{endPage < totalPages && (
|
{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>
|
</ol>
|
||||||
{page < totalPages && (
|
{page < totalPages && (
|
||||||
@@ -300,14 +325,10 @@ const ArchivePage = createClass({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
renderFoundBrews() {
|
renderFoundBrews() {
|
||||||
const { title, brewCollection, error, searching } =
|
const { title, brewCollection, error, searching } = this.state;
|
||||||
this.state;
|
|
||||||
|
|
||||||
if (searching) {
|
if (searching) {
|
||||||
return (
|
return (
|
||||||
@@ -333,10 +354,12 @@ const ArchivePage = createClass({
|
|||||||
errorMessage = "404 - We didn't find any brew";
|
errorMessage = "404 - We didn't find any brew";
|
||||||
break;
|
break;
|
||||||
case '503':
|
case '503':
|
||||||
errorMessage = "503 - Service Unavailable, try again later, sorry.";
|
errorMessage =
|
||||||
|
'503 - Service Unavailable, try again later, sorry.';
|
||||||
break;
|
break;
|
||||||
case '500':
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
errorMessage = 'An unexpected error occurred';
|
errorMessage = 'An unexpected error occurred';
|
||||||
|
|||||||
Reference in New Issue
Block a user