Skip to content

Commit

Permalink
feat: allow extending the includes used by PollListState (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland authored Oct 7, 2024
1 parent 452deac commit c86833e
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit c86833e

Please sign in to comment.