fix(tags): not all tags are loaded in the permission grid (#3804)

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
Sami Mazouz 2023-04-21 07:38:09 +01:00 committed by GitHub
parent 8576df1a43
commit 803f0cd0f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -19,7 +19,6 @@ export default function () {
extend(PermissionGrid.prototype, 'oncreate', function () {
app.tagList.load().then(() => {
this.loading = false;
m.redraw();
});
});

View File

@ -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<string>;
async load(includes: string[] = []): Promise<Tag[]> {
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<Tag>('tags'));
}
return app.store.find<Tag[]>('tags', { include: unloadedIncludes.join(',') }).then((val) => {
unloadedIncludes.forEach((include) => this.loadedIncludes.add(include));
return this.query(unloadedIncludes);
}
async query(includes: string[] = []): Promise<Tag[]> {
this.loadedIncludes ??= new Set();
return app.store.find<Tag[]>('tags', { include: includes.join(',') }).then((val) => {
includes.forEach((include) => this.loadedIncludes!.add(include));
return val;
});
}