-
-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cbdfb6
commit 6b7ee14
Showing
3 changed files
with
89 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,37 @@ | ||
import type ForumApplication from 'flarum/forum/ForumApplication'; | ||
import type Flag from '../models/Flag'; | ||
import type Post from 'flarum/common/models/Post'; | ||
import PaginatedListState from 'flarum/common/states/PaginatedListState'; | ||
|
||
export default class FlagListState { | ||
export default class FlagListState extends PaginatedListState<Flag> { | ||
public app: ForumApplication; | ||
public loading = false; | ||
public cache: Flag[] | null = null; | ||
public index: Post | false | null = null; | ||
|
||
constructor(app: ForumApplication) { | ||
super({}, 1, null); | ||
this.app = app; | ||
} | ||
|
||
get type(): string { | ||
return 'flags'; | ||
} | ||
|
||
/** | ||
* Load flags into the application's cache if they haven't already | ||
* been loaded. | ||
*/ | ||
load() { | ||
if (this.cache && !this.app.session.user!.attribute<number>('newFlagCount')) { | ||
return; | ||
load(): Promise<void> { | ||
if (this.app.session.user?.attribute<number>('newFlagCount')) { | ||
this.pages = []; | ||
this.location = { page: 1 }; | ||
} | ||
|
||
this.loading = true; | ||
m.redraw(); | ||
if (this.pages.length > 0) { | ||
return Promise.resolve(); | ||
} | ||
|
||
this.app.store | ||
.find<Flag[]>('flags') | ||
.then((flags) => { | ||
this.app.session.user!.pushAttributes({ newFlagCount: 0 }); | ||
this.cache = flags.sort((a, b) => b.createdAt()!.getTime() - a.createdAt()!.getTime()); | ||
}) | ||
.catch(() => {}) | ||
.then(() => { | ||
this.loading = false; | ||
m.redraw(); | ||
}); | ||
return super.loadNext(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters