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 {Component, html} from 'htm/preact';
|
||||||
|
|
||||||
import debounce from '../utilities/debounce.js';
|
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>;
|
type Props = Record<string, unknown>;
|
||||||
|
|
||||||
|
@ -97,11 +100,13 @@ export default class SearchBar extends Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const resultAmount = this.state.searchResults.length;
|
const resultAmount = this.state.searchResults.length;
|
||||||
if (resultAmount > 0 && resultAmount % 25 === 0) {
|
if (resultAmount > 0 && resultAmount % searchLimit === 0) {
|
||||||
results.push(
|
results.push(
|
||||||
html`
|
html`
|
||||||
<li class="search-state">
|
<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>
|
</li>
|
||||||
`,
|
`,
|
||||||
);
|
);
|
||||||
|
|
|
@ -17,12 +17,14 @@ export type SearchResult = {
|
||||||
title: string;
|
title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const searchLimit = 25;
|
||||||
|
|
||||||
export default async function searchReleases(
|
export default async function searchReleases(
|
||||||
query: string,
|
query: string,
|
||||||
offset?: number,
|
offset?: number,
|
||||||
): Promise<SearchResult[]> {
|
): Promise<SearchResult[]> {
|
||||||
query = encodeURIComponent(query);
|
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) {
|
if (offset !== undefined) {
|
||||||
url += `&offset=${offset}`;
|
url += `&offset=${offset}`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue