1
Fork 0

Add an explicit search limit.

This commit is contained in:
Bauke 2022-02-05 14:16:58 +01:00
parent 6d121fb7b4
commit 85469eabf7
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 11 additions and 4 deletions

View File

@ -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>
`,
);

View File

@ -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}`;
}