Skip to content

Commit

Permalink
fix(search): correction tentative résultats doublons aléatoire #28
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruze committed May 28, 2024
1 parent 7668dda commit 789190d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions public/js/search-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PageFinder {
this.filterTagsEl = document.querySelector(SEARCH_FILTER_TAGS_SELECTOR);

this.searchResults = [];
this.start = 0;
}

/**
Expand All @@ -41,16 +42,16 @@ class PageFinder {
const filters = this.getFiltersFromResults(await Promise.all(this.searchResults.map((r) => r.data())));

// nouveaux résultats donc on les nettoie et on les affiche
let start = 0;
let paginatedResults = await Promise.all(this.searchResults.slice(start, start + RESULTS_PER_PAGE).map((r) => r.data()));
this.start = 0;
let paginatedResults = await Promise.all(this.searchResults.slice(this.start, this.start + RESULTS_PER_PAGE).map((r) => r.data()));

await this.populateSearchResults(paginatedResults, true);

// chargement des éléments de plus de RESULTS_PER_PAGE au scroll
window.addEventListener("scroll", async () => {
if (this._bottomIsReached()) {
start += RESULTS_PER_PAGE;
paginatedResults = await Promise.all(this.searchResults.slice(start, start + RESULTS_PER_PAGE).map((r) => r.data()));
this.start += RESULTS_PER_PAGE;
paginatedResults = await Promise.all(this.searchResults.slice(this.start, this.start + RESULTS_PER_PAGE).map((r) => r.data()));
await this.populateSearchResults(paginatedResults);
}
});
Expand Down

0 comments on commit 789190d

Please sign in to comment.