decide.nolog.cz/app/components/poll-evaluation-participants-table.ts
Jeldrik Hanschke f0cff27e99
Convert to TypeScript (#713)
* setup typescript

* covert to TypeScript
2023-10-29 19:16:33 +01:00

37 lines
949 B
TypeScript

import Component from '@glimmer/component';
import type Poll from 'croodle/models/poll';
import { DateTime } from 'luxon';
export interface PollEvaluationParticipantsTableSignature {
Args: {
poll: Poll;
};
}
export default class PollEvaluationParticipantsTable extends Component<PollEvaluationParticipantsTableSignature> {
get optionsPerDay() {
const { poll } = this.args;
const optionsPerDay = new Map();
for (const option of poll.options) {
optionsPerDay.set(
option.day,
optionsPerDay.has(option.day) ? optionsPerDay.get(option.day) + 1 : 0,
);
}
return new Map(
Array.from(optionsPerDay.entries()).map(([dayString, count]) => [
DateTime.fromISO(dayString).toJSDate(),
count,
]),
);
}
get usersSorted() {
const { poll } = this.args;
return Array.from(poll.users).sort((a, b) =>
a.creationDate > b.creationDate ? 1 : -1,
);
}
}