import {Component, Input} from '@angular/core'; interface VoteChoice { votesCount: { yes: number no: number maybe: number notAnswered: number }; text?: string; date?: Date; answer: 'yes' | 'no' | 'maybe' | null; simpleAnswer: boolean; // enable if we display only a togglable "yes" } /** * each vote choice takes a configuration from the container of all choices. * this component is used to select a date choice, or a text answer */ @Component({ selector: 'framadate-vote-choice', templateUrl: './vote-choice.component.html', styleUrls: ['./vote-choice.component.scss'] }) export class VoteChoiceComponent { @Input() choice: VoteChoice = { date: new Date(), text: 'description ', votesCount: { yes: 0, no: 0, maybe: 0, notAnswered: 0 }, simpleAnswer: false, answer: null }; constructor() { } setAnswserTo(newAnswer: 'yes' | 'no' | 'maybe' | null) { if (this.choice.simpleAnswer) { // only toggle yes to no if (this.choice.answer && this.choice.answer === 'yes') { this.choice.answer = 'no'; } else { this.choice.answer = 'yes'; } } else { this.choice.answer = newAnswer; } } }