Skip to content

Commit

Permalink
Merge pull request #460 from SharebookBR/meetup-sympla-prioridade
Browse files Browse the repository at this point in the history
Paginação de meetups no front.
  • Loading branch information
raffacabofrio authored Feb 5, 2023
2 parents ae9479e + b63249a commit 5372180
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/app/components/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ <h1 class="text-center display-4 meetup">Meetups em destaque</h1>

<app-card-meetup [meetup]="meetup" *ngFor="let meetup of meetups"></app-card-meetup>

<div class="meetup" *ngIf="showButtonAllMeetups">
<button mat-flat-button color="primary" (click)="showAllMetups()">Mostrar todos os Meetups</button>
<div class="meetup" *ngIf="showButtonMoreMeetups">
<button mat-flat-button color="primary" (click)="showMoreMetups()" style="margin-left: 82px">
Carregar mais Meetups...
</button>
</div>

<div style="clear: both; height: 20px"></div>
Expand Down
21 changes: 10 additions & 11 deletions src/app/components/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export class HomeComponent implements OnInit, OnDestroy {
public hasBook: Boolean = true;

public meetups: Meetup[] = [];
public meetupsAll: Meetup[] = [];
public hasMeetup: boolean = true;
public showButtonAllMeetups: boolean = true;
public meetupsCurrentPage: number = 1;
public meetupsPerPage: number = 10;
public showButtonMoreMeetups: boolean = true;

private _destroySubscribes$ = new Subject<void>();

Expand All @@ -43,20 +43,19 @@ export class HomeComponent implements OnInit, OnDestroy {

getMeetups() {
this._scMeetup
.getAll()
.get(this.meetupsCurrentPage, this.meetupsPerPage)
.pipe(takeUntil(this._destroySubscribes$))
.subscribe((meetups) => {
this.meetupsAll = meetups.items;
this.hasMeetup = meetups.items.length > 0 ? true : false;
this.meetups.push(...meetups.items);

this.meetupsAll.sort((a, b) => (a.startDate > b.startDate ? -1 : 0));
this.meetups = this.meetupsAll.slice(0, 5);
const maxPage = Math.ceil(meetups.totalItems / meetups.itemsPerPage);
this.showButtonMoreMeetups = this.meetupsCurrentPage < maxPage;
});
}

showAllMetups() {
this.meetups = this.meetupsAll;
this.showButtonAllMeetups = false;
showMoreMetups() {
this.meetupsCurrentPage++;
this.getMeetups();
}

ngOnDestroy() {
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/services/meetup/meetup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class MeetupService {
private config: AppConfig
) {}

public getAll(): Observable<MeetupList> {
return this._http.get<MeetupList>(`${this.config.apiEndpoint}/Meetup`);
public get(page: number, pageSize: number): Observable<MeetupList> {
return this._http.get<MeetupList>(`${this.config.apiEndpoint}/Meetup?page=${page}&pagesize=${pageSize}`);
}

public search(criteria: string): Observable<Meetup[]> {
Expand Down

0 comments on commit 5372180

Please sign in to comment.