Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow extending the includes used by PollListState #99

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion js/src/forum/states/PollListState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class PollListState<P extends PollListParams = PollListParams> ex

requestParams(): PaginatedListRequestParams {
const params = {
include: this.params.include || ['options', 'votes'],
include: this.requestIncludes(),
filter: this.params.filter || {},
sort: this.sortMap()[this.params.sort ?? ''],
};
Expand All @@ -38,6 +38,20 @@ export default class PollListState<P extends PollListParams = PollListParams> ex
return params;
}

includes(): string[] {
return ['options', 'votes'];
}

private requestIncludes(): string {
const standard = this.includes();

// merge the standard includes with the custom includes
const merged = [...standard, ...(this.params.include || [])];

// return as a comma separated string
return merged.join(',');
}

protected loadPage(page: number = 1): Promise<ApiResponsePlural<Poll>> {
const preloadedPolls = app.preloadedApiDocument<Poll[]>();

Expand Down
Loading