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

59 lines
1.6 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: '',
};
2022-03-22 11:53:45 +01:00
display_comment_date: boolean = false;
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-15 12:37:37 +01:00
this.pollService
.addComment({
2022-02-14 14:37:42 +01:00
pseudo: this.storageService.vote_stack.pseudo,
text: this.storageService.vote_stack.comment,
})
2022-02-08 13:05:47 +01:00
.then((resp) => {
2022-02-14 14:37:42 +01:00
console.log('resp', resp);
// this.poll.comments.push()
2022-02-08 13:05:47 +01:00
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
}