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

fix(openchallenges): change paginator variable to dynamic rendering #2426

Merged
merged 4 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ <h3>
/>
</div>
<openchallenges-paginator
*ngIf="challenges.length > 0"
#paginator
[pageNumber]="selectedPageNumber || defaultPageNumber"
[pageSize]="selectedPageSize || defaultPageSize"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class ChallengeSearchComponent
defaultSortedBy: ChallengeSort = 'relevance';
defaultPageNumber = 0;
defaultPageSize = 24;
@ViewChild('paginator', { static: true }) paginator!: PaginatorComponent;
@ViewChild('paginator', { static: false }) paginator!: PaginatorComponent;

// define filters
sortFilters: Filter[] = challengeSortFilter;
Expand Down Expand Up @@ -208,7 +208,7 @@ export class ChallengeSearchComponent
);
this.searchedTerms = params['searchTerms'];
this.selectedPageNumber = +params['pageNumber'] || this.defaultPageNumber;
this.selectedPageSize = +params['pageSize'] || this.defaultPageSize;
this.selectedPageSize = this.defaultPageSize; // no available pageSize options for users
this.sortedBy = params['sort'] || this.defaultSortedBy;

const defaultQuery: ChallengeSearchQuery = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ <h3>
/>
</div>
<openchallenges-paginator
*ngIf="organizationCards.length > 0"
#paginator
[pageNumber]="selectedPageNumber || defaultPageNumber"
[pageSize]="selectedPageSize || defaultPageSize"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class OrgSearchComponent implements OnInit, AfterContentInit, OnDestroy {
defaultSortedBy: OrganizationSort = 'challenge_count';
defaultPageNumber = 0;
defaultPageSize = 24;
@ViewChild('paginator', { static: true }) paginator!: PaginatorComponent;
@ViewChild('paginator', { static: false }) paginator!: PaginatorComponent;

// define filters
sortFilters: Filter[] = organizationSortFilter;
Expand Down Expand Up @@ -163,7 +163,7 @@ export class OrgSearchComponent implements OnInit, AfterContentInit, OnDestroy {
this.selectedCategories = this.splitParam(params['categories']);
this.searchedTerms = params['searchTerms'];
this.selectedPageNumber = +params['pageNumber'] || this.defaultPageNumber;
this.selectedPageSize = +params['pageSize'] || this.defaultPageSize;
this.selectedPageSize = this.defaultPageSize; // no available pageSize options for users
this.sortedBy = params['sort'] || this.defaultSortedBy;

const defaultQuery: OrganizationSearchQuery = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
[showCurrentPageReport]="true"
currentPageReportTemplate="Showing {first} to {last} of {totalRecords} results"
(onPageChange)="onPageChange($event)"
[alwaysShow]="false"
></p-paginator>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Output,
EventEmitter,
ViewChild,
OnInit,
} from '@angular/core';
import {
Paginator,
Expand All @@ -18,7 +19,7 @@ import {
templateUrl: './paginator.component.html',
styleUrls: ['./paginator.component.scss'],
})
export class PaginatorComponent {
export class PaginatorComponent implements OnInit {
@Input({ required: true }) pageNumber = 0; // index of the new page
@Input({ required: false }) pageLinkSize = 5;
@Input({ required: true }) pageSize = 0; // number of items to display in new page
Expand All @@ -29,10 +30,9 @@ export class PaginatorComponent {

itemIndex = 0; // index of the first item in the new page

// change itemIndex's value will not dynamically trigger selection updates - seems a primeng issue
// ngOnInit(): void {
// this.itemIndex = this.pageNumber * this.pageSize;
// }
ngOnInit(): void {
this.itemIndex = this.pageNumber * this.pageSize;
}

onPageChange(event: any): void {
this.pageChange.emit(event);
Expand Down