This commit is contained in:
1 parent
e85e4d74ea
commit
2e4ed76121
378 files changed
+22404
-20686
No files matched your search
@@ -1,16 +1,16 @@
|
||||
'use client'
|
||||
"use client";
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
|
||||
interface QuestionResult {
|
||||
id: number
|
||||
question: string
|
||||
options: string
|
||||
votes: string[] // array of answer strings
|
||||
id: number;
|
||||
question: string;
|
||||
options: string;
|
||||
votes: string[]; // array of answer strings
|
||||
}
|
||||
|
||||
interface Props {
|
||||
questions: QuestionResult[]
|
||||
questions: QuestionResult[];
|
||||
}
|
||||
|
||||
export function PollResultsView({ questions }: Props) {
|
||||
@@ -21,14 +21,14 @@ export function PollResultsView({ questions }: Props) {
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
{questions.map((q) => {
|
||||
const options = q.options.split('\n').filter(Boolean)
|
||||
const totalVotes = q.votes.length
|
||||
const options = q.options.split("\n").filter(Boolean);
|
||||
const totalVotes = q.votes.length;
|
||||
|
||||
// Count votes per option
|
||||
const voteCounts = new Map<string, number>()
|
||||
for (const opt of options) voteCounts.set(opt, 0)
|
||||
const voteCounts = new Map<string, number>();
|
||||
for (const opt of options) voteCounts.set(opt, 0);
|
||||
for (const vote of q.votes) {
|
||||
voteCounts.set(vote, (voteCounts.get(vote) ?? 0) + 1)
|
||||
voteCounts.set(vote, (voteCounts.get(vote) ?? 0) + 1);
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -37,8 +37,8 @@ export function PollResultsView({ questions }: Props) {
|
||||
{options.length > 0 ? (
|
||||
<div className="space-y-2">
|
||||
{options.map((opt) => {
|
||||
const count = voteCounts.get(opt) ?? 0
|
||||
const pct = totalVotes > 0 ? Math.round((count / totalVotes) * 100) : 0
|
||||
const count = voteCounts.get(opt) ?? 0;
|
||||
const pct = totalVotes > 0 ? Math.round((count / totalVotes) * 100) : 0;
|
||||
return (
|
||||
<div key={opt}>
|
||||
<div className="flex justify-between text-xs mb-1">
|
||||
@@ -54,21 +54,19 @@ export function PollResultsView({ questions }: Props) {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-sm text-muted-foreground">
|
||||
{totalVotes} free-text responses
|
||||
</div>
|
||||
<div className="text-sm text-muted-foreground">{totalVotes} free-text responses</div>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground mt-2">
|
||||
{totalVotes} total vote{totalVotes !== 1 ? 's' : ''}
|
||||
{totalVotes} total vote{totalVotes !== 1 ? "s" : ""}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
})}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user