Skip to content

Commit

Permalink
Merge pull request #3429 from ita-social-projects/bugfix/#7698-events…
Browse files Browse the repository at this point in the history
…-search

[Bugfix] #7698 search and filtring of saved events
  • Loading branch information
kovalsofiia1 authored Oct 30, 2024
2 parents 4c0927b + f7f0c63 commit ead8836
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class EventsListComponent implements OnInit, OnDestroy {
private page = 0;
private eventsPerPage = 6;
private searchResultSubscription: Subscription;
private searchQuery: string;

constructor(
private store: Store,
Expand Down Expand Up @@ -91,16 +92,16 @@ export class EventsListComponent implements OnInit, OnDestroy {
this.searchResultSubscription.unsubscribe();
}
this.cleanEventList();
value.trim() !== '' ? this.searchEventsByTitle(value.trim()) : this.getEvents();
this.searchQuery = value.trim();
value.trim() !== '' ? this.searchEventsByTitle() : this.getEvents();
});
}

getEvents(): void {
if (this.bookmarkSelected) {
this.getUserFavoriteEvents();
} else {
const searchTitle = this.searchEventControl.value.trim();
this.searchEventsByTitle(searchTitle);
this.searchEventsByTitle();
}
this.page++;
}
Expand Down Expand Up @@ -329,12 +330,12 @@ export class EventsListComponent implements OnInit, OnDestroy {
this.destroyed$.complete();
}

private searchEventsByTitle(searchTitle: string): void {
private searchEventsByTitle(): void {
if (this.searchResultSubscription) {
this.searchResultSubscription.unsubscribe();
}

this.searchResultSubscription = this.eventService.getEvents(this.getEventsHttpParams(searchTitle)).subscribe((res) => {
this.searchResultSubscription = this.eventService.getEvents(this.getEventsHttpParams()).subscribe((res) => {
this.isLoading = false;
if (res.page.length > 0) {
this.countOfEvents = res.totalElements;
Expand All @@ -347,7 +348,7 @@ export class EventsListComponent implements OnInit, OnDestroy {
}

private getUserFavoriteEvents(): void {
this.eventService.getUserFavoriteEvents(this.page, this.eventsPerPage, this.userId).subscribe((res) => {
this.eventService.getEvents(this.getEventsHttpParams()).subscribe((res) => {
this.isLoading = false;
this.eventsList.push(...res.page);
this.page++;
Expand Down Expand Up @@ -392,12 +393,12 @@ export class EventsListComponent implements OnInit, OnDestroy {
this.countOfEvents = 0;
}

private getEventsHttpParams(title: string): HttpParams {
private getEventsHttpParams(): HttpParams {
let params = new HttpParams().append('page', this.page.toString()).append('size', this.eventsPerPage.toString());

const paramsToAdd = [
this.appendIfNotEmpty('user-id', this.userId?.toString()),
this.appendIfNotEmpty('title', title),
this.appendIfNotEmpty('title', this.searchQuery),
this.appendIfNotEmpty('type', this.getTypeFilter()),
this.appendIfNotEmpty(
'cities',
Expand All @@ -411,7 +412,9 @@ export class EventsListComponent implements OnInit, OnDestroy {
),
this.appendIfNotEmpty(
'statuses',
this.selectedStatusFiltersList.filter((status) => status !== 'Any status' && status !== 'Будь-який статус')
this.selectedStatusFiltersList
.filter((status) => status !== 'Any status' && status !== 'Будь-який статус')
.concat(this.bookmarkSelected ? ['SAVED'] : [])
),
this.appendIfNotEmpty(
'tags',
Expand Down

0 comments on commit ead8836

Please sign in to comment.