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

69 lines
2.0 KiB
TypeScript

import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { Poll } from '../../core/models/poll.model';
import { ModalService } from '../../core/services/modal.service';
import { PollService } from '../../core/services/poll.service';
@Component({
selector: 'app-consultation',
templateUrl: './consultation.component.html',
styleUrls: ['./consultation.component.scss'],
})
export class ConsultationComponent implements OnInit, OnDestroy {
public isCompactMode = true;
public poll: Poll;
public pollSlug: string;
public passHash: string;
public fetching: boolean = true;
public isArchived: boolean;
private routeSubscription: Subscription;
constructor(
private router: Router,
private _Activatedroute: ActivatedRoute,
public pollService: PollService,
private modalService: ModalService
) {}
ngOnInit(): void {
console.log('constultation de poll');
this.pollService.poll.subscribe((newpoll: Poll) => {
this.poll = newpoll;
});
this._Activatedroute.paramMap.subscribe((params) => {
console.log('params', params);
this.pollSlug = params.get('slug');
this.passHash = params.get('hash');
console.log('hash, slug', this.passHash, this.pollSlug);
if (this.passHash) {
this.pollService.loadPollBySlugWithPasswordHash(this.pollSlug, this.passHash);
} else {
this.pollService.loadPollBySlug(this.pollSlug).then((resp) => {
console.log('resp', resp);
this.fetching = false;
});
}
});
// if (!this.userService.isCurrentUserIdentifiable()) {
// this.modalService.openModal(SettingsComponent);
// }
// this.routeSubscription = this.activatedRoute.data.subscribe((data: { poll: Poll }) => {
// if (data.poll) {
// this.poll = data.poll;
// this.isArchived = PollConfiguration.isArchived(data.poll.configuration);
// } else {
// this.router.navigate(['/page-not-found']);
// }
// });
}
ngOnDestroy(): void {
if (this.routeSubscription) {
this.routeSubscription.unsubscribe();
}
}
}