2020-04-14 11:28:33 +02:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2020-04-20 18:11:00 +02:00
|
|
|
import { BaseComponent } from '../../example/base-page/base.component';
|
|
|
|
import { ConfigService } from '../../../services/config.service';
|
2020-05-12 19:16:23 +02:00
|
|
|
import { mockComments } from '../../../mocks/mock-comments';
|
2020-04-14 11:28:33 +02:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
2021-04-29 10:41:47 +02:00
|
|
|
import { environment } from '../../../../../src/environments/environment';
|
2020-05-12 19:16:23 +02:00
|
|
|
import { mockPoll3 } from '../../../mocks/mock-poll3';
|
2020-01-15 17:55:22 +01:00
|
|
|
|
|
|
|
@Component({
|
2020-04-22 12:56:18 +02:00
|
|
|
selector: 'app-poll-display',
|
2020-04-21 10:50:26 +02:00
|
|
|
templateUrl: './poll-display.component.html',
|
|
|
|
styleUrls: ['./poll-display.component.scss'],
|
2020-01-15 17:55:22 +01:00
|
|
|
})
|
|
|
|
export class PollDisplayComponent extends BaseComponent implements OnInit {
|
2020-04-21 10:50:26 +02:00
|
|
|
comments = mockComments;
|
2020-01-16 10:20:15 +01:00
|
|
|
|
2020-04-21 10:50:26 +02:00
|
|
|
constructor(public config: ConfigService, private router: Router, public activeRoute: ActivatedRoute) {
|
|
|
|
super(config);
|
|
|
|
this.activeRoute.paramMap.subscribe((params) => {
|
|
|
|
console.log('params', params);
|
|
|
|
this.config.pollId = params.get('poll');
|
|
|
|
this.config.pollSlug = params.get('pollSlug');
|
|
|
|
if (!this.config.loading) {
|
|
|
|
this.fetchPoll();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-01-15 17:55:22 +01:00
|
|
|
|
2020-05-01 19:10:17 +02:00
|
|
|
ngOnInit(): void {}
|
2020-01-22 16:49:15 +01:00
|
|
|
|
2021-04-30 10:59:46 +02:00
|
|
|
// fetch poll with its ID or custom_url.
|
2020-04-21 10:50:26 +02:00
|
|
|
fetchPoll() {
|
|
|
|
const id = this.activeRoute.snapshot.params.poll;
|
|
|
|
const pollSlug = this.activeRoute.snapshot.params.pollSlug;
|
2020-01-22 14:42:46 +01:00
|
|
|
|
2020-04-21 10:50:26 +02:00
|
|
|
if (!environment.production) {
|
|
|
|
console.log('mockPoll3', mockPoll3);
|
|
|
|
this.config.currentPoll = mockPoll3;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (id) {
|
|
|
|
this.config.loading = true;
|
|
|
|
// store it in the poll property here
|
|
|
|
this.config.getPollById(id).subscribe(
|
|
|
|
(res: any) => {
|
|
|
|
console.log('res', res);
|
|
|
|
this.config.updateCurrentPollFromResponse(res);
|
|
|
|
this.config.loading = false;
|
|
|
|
},
|
|
|
|
(e) => {
|
|
|
|
// handle need for a password
|
|
|
|
console.log('e', e);
|
|
|
|
this.config.handleError(e);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else if (pollSlug) {
|
|
|
|
this.config.loading = true;
|
|
|
|
this.config.getPollByURL(pollSlug).subscribe(
|
|
|
|
(res: any) => {
|
|
|
|
this.config.loading = false;
|
|
|
|
this.config.updateCurrentPollFromResponse(res);
|
|
|
|
},
|
|
|
|
(e) => {
|
|
|
|
// handle need for a password
|
|
|
|
this.config.handleError(e);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-01-15 17:55:22 +01:00
|
|
|
}
|