funky-framadate-front/src/app/features/participation/participation.component.ts

47 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-06-18 16:15:26 +02:00
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable, Subscription } from 'rxjs';
2020-05-05 18:17:12 +02:00
import { Poll } from '../../core/models/poll.model';
2020-05-12 19:16:23 +02:00
import { User } from '../../core/models/user.model';
2020-05-05 18:17:12 +02:00
import { ModalService } from '../../core/services/modal.service';
import { UserService } from '../../core/services/user.service';
import { SettingsComponent } from '../../shared/components/settings/settings.component';
2020-04-22 12:56:18 +02:00
@Component({
selector: 'app-participation',
templateUrl: './participation.component.html',
styleUrls: ['./participation.component.scss'],
})
2020-06-18 16:15:26 +02:00
export class ParticipationComponent implements OnInit, OnDestroy {
public poll: Poll;
2020-05-12 19:16:23 +02:00
public _user: Observable<User> = this.userService.user;
2020-06-18 16:15:26 +02:00
private routeSubscription: Subscription;
2020-05-05 18:17:12 +02:00
constructor(
2020-06-18 16:15:26 +02:00
private router: Router,
private activatedRoute: ActivatedRoute,
2020-05-05 18:17:12 +02:00
private userService: UserService,
private modalService: ModalService
) {}
2020-04-22 12:56:18 +02:00
2020-05-05 18:17:12 +02:00
ngOnInit(): void {
if (!this.userService.isCurrentUserIdentifiable()) {
this.modalService.openModal(SettingsComponent);
2020-05-05 18:17:12 +02:00
}
2020-06-18 16:15:26 +02:00
this.routeSubscription = this.activatedRoute.data.subscribe((data: { poll: Poll }) => {
if (data.poll) {
this.poll = data.poll;
} else {
this.router.navigate(['/page-not-found']);
}
});
}
ngOnDestroy(): void {
if (this.routeSubscription) {
this.routeSubscription.unsubscribe();
}
2020-05-05 18:17:12 +02:00
}
2020-04-22 12:56:18 +02:00
}