|
|
@@ -0,0 +1,52 @@
|
|
|
+import { Component } from '@angular/core';
|
|
|
+import { Subject } from 'rxjs';
|
|
|
+import { EventsApiService } from 'src/app/events-api.service';
|
|
|
+import { EventSearchParams } from 'src/app/events/event-search-params';
|
|
|
+import { GroupEvent } from 'src/app/events/group-event';
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-events-page',
|
|
|
+ templateUrl: './events-page.component.html',
|
|
|
+ styleUrls: ['./events-page.component.scss']
|
|
|
+})
|
|
|
+export class EventsPageComponent {
|
|
|
+ private _groupEvents: GroupEvent[] = [];
|
|
|
+ public groupEvents: Subject<GroupEvent[]> = new Subject<GroupEvent[]>();
|
|
|
+ public hasMore: boolean = false;
|
|
|
+
|
|
|
+ public showMyEvents: boolean = false;
|
|
|
+ public titleFilter: string = '';
|
|
|
+
|
|
|
+ private searchParams: EventSearchParams = new EventSearchParams();
|
|
|
+
|
|
|
+ public constructor(
|
|
|
+ private readonly eventsApi: EventsApiService
|
|
|
+ ) {
|
|
|
+ this.updateEvents();
|
|
|
+ }
|
|
|
+
|
|
|
+ public search(event: SubmitEvent): void {
|
|
|
+ this.searchParams = new EventSearchParams();
|
|
|
+ this.searchParams.owner = this.showMyEvents ? 'me' : undefined;
|
|
|
+ this.searchParams.filter = this.titleFilter ? this.titleFilter : undefined;
|
|
|
+ this.updateEvents();
|
|
|
+ }
|
|
|
+
|
|
|
+ public loadMore(): void {
|
|
|
+ this.searchParams.page++;
|
|
|
+ this.updateEvents();
|
|
|
+ }
|
|
|
+
|
|
|
+ private updateEvents(): void {
|
|
|
+ this.eventsApi.getEvents(this.searchParams)
|
|
|
+ .then(eventsPage => {
|
|
|
+ if (this.searchParams.page === 0) {
|
|
|
+ this._groupEvents = eventsPage.items;
|
|
|
+ } else {
|
|
|
+ this._groupEvents.push(...eventsPage.items);
|
|
|
+ }
|
|
|
+ this.hasMore = eventsPage.hasMore;
|
|
|
+ this.groupEvents.next(this._groupEvents);
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|