From 279f40004f091ea856a1165ea13772bd00468a83 Mon Sep 17 00:00:00 2001 From: Bauke Date: Thu, 3 Feb 2022 12:23:10 +0100 Subject: [PATCH] Add a load more button for search results (#16). --- source/ts/components/search-bar.ts | 28 ++++++++++++++++++++++++++++ source/ts/utilities/search.ts | 7 ++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/source/ts/components/search-bar.ts b/source/ts/components/search-bar.ts index d6595c1..33a148f 100644 --- a/source/ts/components/search-bar.ts +++ b/source/ts/components/search-bar.ts @@ -24,6 +24,23 @@ export default class SearchBar extends Component { }; } + searchMore = async (): Promise => { + if (this.state.searchValue.length === 0) { + this.setState({searchResults: [], searchState: 'waiting'}); + return; + } + + this.setState({ + searchResults: [ + ...this.state.searchResults, + ...(await searchReleases( + this.state.searchValue, + this.state.searchResults.length, + )), + ], + }); + }; + searchQuery = async (): Promise => { if (this.state.searchValue.length === 0) { this.setState({searchResults: [], searchState: 'waiting'}); @@ -79,6 +96,17 @@ export default class SearchBar extends Component { ); } + const resultAmount = this.state.searchResults.length; + if (resultAmount > 0 && resultAmount % 25 === 0) { + results.push( + html` +
  • + +
  • + `, + ); + } + return html`