funky-framadate-front/src/app/pages/poll-display/poll-display.component.ts

57 lines
1.8 KiB
TypeScript

import {Component, OnInit} from '@angular/core';
import {BaseComponent} from "../base-page/base.component";
import {ConfigService} from "../../services/config.service";
import {mockComments} from "../../config/mocks/mock-comments";
import {ActivatedRoute} from "@angular/router";
@Component({
selector: 'framadate-poll-display',
templateUrl: './poll-display.component.html',
styleUrls: ['./poll-display.component.scss']
})
export class PollDisplayComponent extends BaseComponent implements OnInit {
comments = mockComments;
constructor(public config: ConfigService,
public activeRoute: ActivatedRoute) {
super(config);
}
ngOnInit() {
this.config.currentPoll;
// fetch poll with its ID or slug.
const id = this.activeRoute.snapshot.params.poll;
const pollSlug = this.activeRoute.snapshot.params.pollSlug;
if (id) {
// store it in the poll property here
this.config.getPollById(id).subscribe(
(res: any) => {
this.config.pollId = id;
this.config.currentPoll = res;
this.config.loading = false;
}, (e) => {
// handle need for a password
this.config.handleError(e)
}
);
} else if (pollSlug) {
this.config.getPollByURL(pollSlug).subscribe(
(res: any) => {
this.config.pollId = res.id;
this.config.currentPoll = res;
this.config.loading = false;
}, (e) => {
// handle need for a password
this.config.handleError(e)
}
);
}
}
}