funky-framadate-front/src/app/shared/components/comments/comments.component.ts

53 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-04-26 10:32:42 +02:00
import { Component, Input } from '@angular/core';
2020-05-01 19:10:17 +02:00
import { PollService } from '../../../core/services/poll.service';
2021-04-26 10:32:42 +02:00
import * as moment from 'moment';
import { Stack } from '../../../core/models/stack.model';
import { Poll } from '../../../core/models/poll.model';
2022-02-08 13:05:47 +01:00
import { ApiService } from '../../../core/services/api.service';
import { StorageService } from '../../../core/services/storage.service';
import { ToastService } from '../../../core/services/toast.service';
2020-05-01 19:10:17 +02:00
@Component({
2020-05-12 19:16:23 +02:00
selector: 'app-comments',
templateUrl: './comments.component.html',
styleUrls: ['./comments.component.scss'],
2020-05-01 19:10:17 +02:00
})
2020-05-12 19:16:23 +02:00
export class CommentsComponent {
@Input() public vote_stack: Stack;
@Input() public poll: Poll;
2021-04-26 10:32:42 +02:00
public config: any = {
myName: '',
myEmail: '',
myComment: '',
};
2020-05-01 19:10:17 +02:00
2022-02-08 13:05:47 +01:00
constructor(
private pollService: PollService,
private api: ApiService,
private toastService: ToastService,
private storageService: StorageService
) {}
2021-04-26 10:32:42 +02:00
calculateDaysAgoOfComment(dateAsString) {
let numberOfDays = 0;
if (dateAsString && dateAsString) {
numberOfDays = moment(new Date()).diff(moment(new Date(dateAsString)), 'days');
}
return numberOfDays;
}
addComment() {
2022-02-08 13:05:47 +01:00
this.api
.createComment(this.pollService._poll.getValue().custom_url, this.storageService.vote_stack.comment)
.then((resp) => {
this.toastService.display('commentaire ajouté');
})
.catch((error) => {
this.toastService.display('Erreur', error.message);
});
2021-04-26 10:32:42 +02:00
}
2020-05-01 19:10:17 +02:00
}