From 803f0cd0f4ca2b01f62603b01144655ba6ffffc7 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Fri, 21 Apr 2023 07:38:09 +0100 Subject: [PATCH] fix(tags): not all tags are loaded in the permission grid (#3804) Signed-off-by: Sami Mazouz --- .../js/src/admin/addTagsPermissionScope.tsx | 1 - .../tags/js/src/common/states/TagListState.ts | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/extensions/tags/js/src/admin/addTagsPermissionScope.tsx b/extensions/tags/js/src/admin/addTagsPermissionScope.tsx index af7f01bd9..200cb0d38 100644 --- a/extensions/tags/js/src/admin/addTagsPermissionScope.tsx +++ b/extensions/tags/js/src/admin/addTagsPermissionScope.tsx @@ -19,7 +19,6 @@ export default function () { extend(PermissionGrid.prototype, 'oncreate', function () { app.tagList.load().then(() => { this.loading = false; - m.redraw(); }); }); diff --git a/extensions/tags/js/src/common/states/TagListState.ts b/extensions/tags/js/src/common/states/TagListState.ts index e5a1938b6..e0db4a215 100644 --- a/extensions/tags/js/src/common/states/TagListState.ts +++ b/extensions/tags/js/src/common/states/TagListState.ts @@ -2,17 +2,27 @@ import app from 'flarum/common/app'; import type Tag from '../../common/models/Tag'; export default class TagListState { - loadedIncludes = new Set(); + loadedIncludes?: Set; async load(includes: string[] = []): Promise { - const unloadedIncludes = includes.filter((include) => !this.loadedIncludes.has(include)); + if (!this.loadedIncludes) { + return this.query(includes); + } + + const unloadedIncludes = includes.filter((include) => !this.loadedIncludes!.has(include)); if (unloadedIncludes.length === 0) { return Promise.resolve(app.store.all('tags')); } - return app.store.find('tags', { include: unloadedIncludes.join(',') }).then((val) => { - unloadedIncludes.forEach((include) => this.loadedIncludes.add(include)); + return this.query(unloadedIncludes); + } + + async query(includes: string[] = []): Promise { + this.loadedIncludes ??= new Set(); + + return app.store.find('tags', { include: includes.join(',') }).then((val) => { + includes.forEach((include) => this.loadedIncludes!.add(include)); return val; }); }