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

[Bugfix] #7739 favorite events for not logged in users #3442

Merged
merged 3 commits into from
Nov 10, 2024
Merged
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
@@ -1,15 +1,15 @@
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Addresses, EventListResponse, FilterItem } from '../../models/events.interface';
import { UserOwnAuthService } from '@auth-service/user-own-auth.service';
import { Observable, ReplaySubject, Subscription } from 'rxjs';
import { Observable, ReplaySubject, Subscription, take } from 'rxjs';
import { LocalStorageService } from '@global-service/localstorage/local-storage.service';
import { Store } from '@ngrx/store';
import { IAppState } from 'src/app/store/state/app.state';
import { IEcoEventsState } from 'src/app/store/state/ecoEvents.state';
import { statusFiltersData, timeStatusFiltersData, typeFiltersData } from '../../models/event-consts';
import { Router } from '@angular/router';
import { AuthModalComponent } from '@global-auth/auth-modal/auth-modal.component';
import { MatDialog } from '@angular/material/dialog';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { FormControl, Validators } from '@angular/forms';
import { MatSelect } from '@angular/material/select';
import { Patterns } from 'src/assets/patterns/patterns';
Expand All @@ -35,7 +35,7 @@ export class EventsListComponent implements OnInit, OnDestroy {
searchEventControl = new FormControl('', [Validators.maxLength(30), Validators.pattern(Patterns.NameInfoPattern)]);

eventsList: EventListResponse[] = [];
isLoggedIn: string;
isLoggedIn: boolean;
selectedEventTimeStatusFiltersList: string[] = [];
selectedLocationFiltersList: string[] = [];
selectedStatusFiltersList: string[] = [];
Expand All @@ -59,6 +59,7 @@ export class EventsListComponent implements OnInit, OnDestroy {
private eventsPerPage = 6;
private searchResultSubscription: Subscription;
private searchQuery: string;
private readonly dialogRef: MatDialogRef<unknown>;

constructor(
private store: Store,
Expand Down Expand Up @@ -115,16 +116,25 @@ export class EventsListComponent implements OnInit, OnDestroy {
}

showSelectedEvents(): void {
this.bookmarkSelected = !this.bookmarkSelected;
if (this.bookmarkSelected) {
this.cleanEventList();
this.getUserFavoriteEvents();
if (!this.isLoggedIn) {
this.openAuthModalWindow('sign-in');
this.dialogRef
.afterClosed()
.pipe(take(1))
.subscribe((result) => {
this.isLoggedIn = !!result;
});
} else {
this.cleanEventList();
this.getEvents();
this.toggleEventList();
}
}

private toggleEventList(): void {
this.bookmarkSelected = !this.bookmarkSelected;
this.cleanEventList();
this.getEvents();
}

getUniqueLocations(addresses: Array<Addresses>): FilterItem[] {
const uniqueLocationsName = new Set<string>();
const uniqueLocations: FilterItem[] = [{ type: 'location', nameEn: 'Online', nameUa: 'Онлайн' }];
Expand Down Expand Up @@ -351,7 +361,6 @@ export class EventsListComponent implements OnInit, OnDestroy {
this.eventService.getEvents(this.getEventsHttpParams()).subscribe((res) => {
this.isLoading = false;
this.eventsList.push(...res.page);
this.page++;
this.countOfEvents = res.totalElements;
this.hasNextPage = res.hasNext;
});
Expand Down Expand Up @@ -446,7 +455,7 @@ export class EventsListComponent implements OnInit, OnDestroy {

private checkUserSingIn(): void {
this.userOwnAuthService.credentialDataSubject.subscribe((data) => {
this.isLoggedIn = data?.userId;
this.isLoggedIn = !!data?.userId;
this.userId = data.userId;
this.statusFiltersList = this.userId ? statusFiltersData : statusFiltersData.slice(0, 2);
});
Expand Down
Loading