mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 09:11:40 +08:00
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:
parent
8576df1a43
commit
803f0cd0f4
@ -19,7 +19,6 @@ export default function () {
|
||||
extend(PermissionGrid.prototype, 'oncreate', function () {
|
||||
app.tagList.load().then(() => {
|
||||
this.loading = false;
|
||||
|
||||
m.redraw();
|
||||
});
|
||||
});
|
||||
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user