diff --git a/src/common/item.store.ts b/src/common/item.store.ts index 2b5a736abd..ce5fe75576 100644 --- a/src/common/item.store.ts +++ b/src/common/item.store.ts @@ -97,12 +97,22 @@ export abstract class ItemStore { } protected async loadItems(...args: any[]): Promise; + /** + * Load items to this.items + * @param request Function to return the items to be loaded. + * @param sortItems If true, items will be sorted. + * @param concurrency If true, concurrent loadItems() calls will all be executed. If false, only the first. + * @returns + */ @action - protected async loadItems(request: () => Promise, sortItems = true) { + protected async loadItems(request: () => Promise, sortItems = true, concurrency = false) { if (this.isLoading) { await when(() => !this.isLoading); - return; + // If concurrency for loading is disabled, return instead of loading + if (!concurrency) { + return; + } } this.isLoading = true; diff --git a/src/renderer/components/+catalog/catalog-entity.store.tsx b/src/renderer/components/+catalog/catalog-entity.store.tsx index dd9fc7f0d7..1350573659 100644 --- a/src/renderer/components/+catalog/catalog-entity.store.tsx +++ b/src/renderer/components/+catalog/catalog-entity.store.tsx @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { when, computed, makeObservable, observable, reaction } from "mobx"; +import { computed, makeObservable, observable, reaction } from "mobx"; import { catalogEntityRegistry, CatalogEntityRegistry } from "../../api/catalog-entity-registry"; import type { CatalogEntity } from "../../api/catalog-entity"; import { ItemStore } from "../../../common/item.store"; @@ -65,7 +65,8 @@ export class CatalogEntityStore extends ItemStore this.entities); + // concurrency is true to fix bug if catalog filter is removed and added at the same time + return this.loadItems(() => this.entities, undefined, true); } /** @@ -75,27 +76,11 @@ export class CatalogEntityStore extends ItemStore Promise[] | any>) | (() => CatalogEntityItem[] | any), sortItems = true, + concurrency = false, ) { - if (this.isLoading) { - await when(() => !this.isLoading); - } - - this.isLoading = true; - - try { - let items = await request(); - - if (sortItems) { - items = this.sortItems(items); - } - this.items.replace(items); - - this.isLoaded = true; - } finally { - this.isLoading = false; - } + return super.loadItems(request, sortItems, concurrency); } }