Add an explicit search limit.
This commit is contained in:
parent
6d121fb7b4
commit
85469eabf7
|
@ -1,7 +1,10 @@
|
|||
import {Component, html} from 'htm/preact';
|
||||
|
||||
import debounce from '../utilities/debounce.js';
|
||||
import searchReleases, {SearchResult} from '../utilities/search.js';
|
||||
import searchReleases, {
|
||||
searchLimit,
|
||||
SearchResult,
|
||||
} from '../utilities/search.js';
|
||||
|
||||
type Props = Record<string, unknown>;
|
||||
|
||||
|
@ -97,11 +100,13 @@ export default class SearchBar extends Component<Props, State> {
|
|||
}
|
||||
|
||||
const resultAmount = this.state.searchResults.length;
|
||||
if (resultAmount > 0 && resultAmount % 25 === 0) {
|
||||
if (resultAmount > 0 && resultAmount % searchLimit === 0) {
|
||||
results.push(
|
||||
html`
|
||||
<li class="search-state">
|
||||
<button class="load-more" onClick=${this.searchMore}>Load more…</button>
|
||||
<button class="load-more" onClick=${this.searchMore}>
|
||||
Load more…
|
||||
</button>
|
||||
</li>
|
||||
`,
|
||||
);
|
||||
|
|
|
@ -17,12 +17,14 @@ export type SearchResult = {
|
|||
title: string;
|
||||
};
|
||||
|
||||
export const searchLimit = 25;
|
||||
|
||||
export default async function searchReleases(
|
||||
query: string,
|
||||
offset?: number,
|
||||
): Promise<SearchResult[]> {
|
||||
query = encodeURIComponent(query);
|
||||
let url = `https://musicbrainz.org/ws/2/release?query=${query}`;
|
||||
let url = `https://musicbrainz.org/ws/2/release?query=${query}&limit=${searchLimit}`;
|
||||
if (offset !== undefined) {
|
||||
url += `&offset=${offset}`;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue