From 140e58c5a68db674fc1d240147e4d669b29f2cad Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Fri, 19 Jan 2024 16:01:43 +0100 Subject: [PATCH] [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) --- .../static/src/components/media_dialog/image_selector.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/web_unsplash/static/src/components/media_dialog/image_selector.js b/addons/web_unsplash/static/src/components/media_dialog/image_selector.js index a7bf6da21e7..238c6244c27 100644 --- a/addons/web_unsplash/static/src/components/media_dialog/image_selector.js +++ b/addons/web_unsplash/static/src/components/media_dialog/image_selector.js @@ -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);