diff --git a/framework/core/js/src/forum/states/DiscussionListState.ts b/framework/core/js/src/forum/states/DiscussionListState.ts index 06390e55c..b4a967769 100644 --- a/framework/core/js/src/forum/states/DiscussionListState.ts +++ b/framework/core/js/src/forum/states/DiscussionListState.ts @@ -2,6 +2,12 @@ import app from '../../forum/app'; import PaginatedListState, { Page } from '../../common/states/PaginatedListState'; import Discussion from '../../common/models/Discussion'; +export interface IRequestParams { + include: string[]; + filter: Record; + sort?: string; +} + export default class DiscussionListState extends PaginatedListState { protected extraDiscussions: Discussion[] = []; @@ -13,21 +19,24 @@ export default class DiscussionListState extends PaginatedListState return 'discussions'; } - requestParams() { - const params: any = { include: ['user', 'lastPostedUser'], filter: this.params.filter || {} }; + requestParams(): IRequestParams { + const params: IRequestParams = { + include: ['user', 'lastPostedUser'], + filter: this.params.filter || {}, + }; params.sort = this.sortMap()[this.params.sort]; if (this.params.q) { params.filter.q = this.params.q; - params.include.push('mostRelevantPost', 'mostRelevantPost.user'); } + return params; } - protected loadPage(page: number = 1): any { - const preloadedDiscussions = app.preloadedApiDocument(); + protected loadPage(page: number = 1): Promise { + const preloadedDiscussions = app.preloadedApiDocument() as Discussion[] | null; if (preloadedDiscussions) { this.initialLoading = false; @@ -38,7 +47,7 @@ export default class DiscussionListState extends PaginatedListState return super.loadPage(page); } - clear() { + clear(): void { super.clear(); this.extraDiscussions = []; @@ -65,11 +74,11 @@ export default class DiscussionListState extends PaginatedListState /** * In the last request, has the user searched for a discussion? */ - isSearchResults() { + isSearchResults(): boolean { return !!this.params.q; } - removeDiscussion(discussion: Discussion) { + removeDiscussion(discussion: Discussion): void { for (const page of this.pages) { const index = page.items.indexOf(discussion); @@ -91,7 +100,7 @@ export default class DiscussionListState extends PaginatedListState /** * Add a discussion to the top of the list. */ - addDiscussion(discussion: Discussion) { + addDiscussion(discussion: Discussion): void { this.removeDiscussion(discussion); this.extraDiscussions.unshift(discussion);