import {Component, Input} from '@angular/core'; import {environment} from "../../environments/environment"; 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; constructor() { if (!environment.production) { // demo content for dev env this.choice = { date: new Date(), text: 'description ', simpleAnswer: false } } } 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; } } }