[FIX] web_unsplash: ignore received duplicates
When obtaining several batches of images for the same string query on Unsplash, sometimes the same image appears in several batches. Because of this the `t-foreach` in the `web_unsplash.ImagesListTemplate` template fails when duplicate records appear in the list of images. This commit ignores duplicates received from Unsplash to avoid the issue. task-3637756 closes odoo/odoo#150511 X-original-commit: 78cad00e169e42d13aecf37ffb19615d725f4e2d Signed-off-by: Robin Lejeune (role) <role@odoo.com>
This commit is contained in:
@@ -149,7 +149,10 @@ patch(ImageSelector.prototype, {
|
||||
const { isMaxed, images } = await this.unsplash.getImages(this.state.needle, offset, this.NUMBER_OF_RECORDS_TO_DISPLAY, this.props.orientation);
|
||||
this.state.isFetchingUnsplash = false;
|
||||
this.state.unsplashError = false;
|
||||
const records = images.map(record => {
|
||||
// Ignore duplicates.
|
||||
const existingIds = this.state.unsplashRecords.map(existing => existing.id);
|
||||
const newImages = images.filter(record => !existingIds.includes(record.id));
|
||||
const records = newImages.map(record => {
|
||||
const url = new URL(record.urls.regular);
|
||||
// In small windows, row height could get quite a bit larger than the min, so we keep some leeway.
|
||||
url.searchParams.set('h', 2 * this.MIN_ROW_HEIGHT);
|
||||
|
||||
Reference in New Issue
Block a user