From 12c9d85ba2d1a84756befb24c68d1b4cb0edebe7 Mon Sep 17 00:00:00 2001 From: Younn Olivier Date: Mon, 14 Nov 2022 10:21:15 +0000 Subject: [PATCH] [IMP] web_editor: load more illustrations only when filter is set Before this commit, clicking on the 'load more' button of the media dialog after a search (with no filter set) would load more attachments/illustrations/unsplash records. As illustrations are considered less relevant than attachments/unsplash records, it was decided to load more of them only when the filter is set to "illustrations". When the filter is not set, the 'load more' button will be visible only if there are more attachments or more unsplash images to load (and not visible otherwise, even if there are more illustrations to load). Also, the loadMore override will only perform the query to load more illustrations if the filter is set. A deeper review of the Media Dialog UI will be conducted later. For now, this commit avoids loading too many illustrations, for users that are most of the time more interested in the unsplash results. task-3060679 X-original-commit: 6aaca71a4b2a11ffa80578904bc7c79c1fa0339d Part-of: odoo/odoo#118556 --- .../src/components/media_dialog/image_selector.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/web_editor/static/src/components/media_dialog/image_selector.js b/addons/web_editor/static/src/components/media_dialog/image_selector.js index b67f49aff66..a9cf4dc8f27 100644 --- a/addons/web_editor/static/src/components/media_dialog/image_selector.js +++ b/addons/web_editor/static/src/components/media_dialog/image_selector.js @@ -68,9 +68,8 @@ export class ImageSelector extends FileSelector { } get canLoadMore() { - if (this.state.searchService === 'all') { - return super.canLoadMore || (this.state.libraryResults && this.state.libraryMedia.length < this.state.libraryResults); - } else if (this.state.searchService === 'media-library') { + // The user can load more library media only when the filter is set. + if (this.state.searchService === 'media-library') { return this.state.libraryResults && this.state.libraryMedia.length < this.state.libraryResults; } return super.canLoadMore; @@ -182,7 +181,10 @@ export class ImageSelector extends FileSelector { async loadMore(...args) { await super.loadMore(...args); - if (!this.props.useMediaLibrary) { + if (!this.props.useMediaLibrary + // The user can load more library media only when the filter is set. + || this.state.searchService !== 'media-library' + ) { return; } return this.keepLastLibraryMedia.add(this.fetchLibraryMedia(this.state.libraryMedia.length)).then(({ media }) => {