|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useState } from "react"; |
| 4 | +import { Badge } from "@/components/ui/Badge"; |
| 5 | +import { motion, AnimatePresence } from "framer-motion"; |
| 6 | + |
| 7 | +interface Answer { |
| 8 | + id: string; |
| 9 | + questionText: string; |
| 10 | + correctAnswer: string | null; |
| 11 | + elderAnswer: string | null; |
| 12 | + result: string | null; |
| 13 | + audioUrl: string | null; |
| 14 | + orderIndex: number; |
| 15 | +} |
| 16 | + |
| 17 | +interface QuestionListProps { |
| 18 | + answers: Answer[]; |
| 19 | +} |
| 20 | + |
| 21 | +export function QuestionList({ answers }: QuestionListProps) { |
| 22 | + const [expanded, setExpanded] = useState<string | null>(null); |
| 23 | + |
| 24 | + if (answers.length === 0) { |
| 25 | + return ( |
| 26 | + <p className="text-sm text-gray-500 text-center py-4"> |
| 27 | + No questions in this session |
| 28 | + </p> |
| 29 | + ); |
| 30 | + } |
| 31 | + |
| 32 | + return ( |
| 33 | + <div className="space-y-2"> |
| 34 | + {answers.map((answer) => ( |
| 35 | + <div |
| 36 | + key={answer.id} |
| 37 | + className="rounded-xl border border-white/5 bg-white/[0.03] overflow-hidden" |
| 38 | + > |
| 39 | + <button |
| 40 | + onClick={() => |
| 41 | + setExpanded(expanded === answer.id ? null : answer.id) |
| 42 | + } |
| 43 | + className="w-full flex items-center justify-between px-4 py-3 text-left" |
| 44 | + > |
| 45 | + <div className="flex items-center gap-3 min-w-0"> |
| 46 | + <span className="text-xs text-gray-500 shrink-0"> |
| 47 | + Q{answer.orderIndex + 1} |
| 48 | + </span> |
| 49 | + <span className="text-sm text-gray-300 truncate"> |
| 50 | + {answer.questionText} |
| 51 | + </span> |
| 52 | + </div> |
| 53 | + <div className="flex items-center gap-2 shrink-0 ml-2"> |
| 54 | + {answer.result && ( |
| 55 | + <Badge |
| 56 | + variant={ |
| 57 | + answer.result === "CORRECT" |
| 58 | + ? "success" |
| 59 | + : answer.result === "WRONG" |
| 60 | + ? "danger" |
| 61 | + : "warning" |
| 62 | + } |
| 63 | + > |
| 64 | + {answer.result} |
| 65 | + </Badge> |
| 66 | + )} |
| 67 | + <svg |
| 68 | + className={`w-4 h-4 text-gray-500 transition-transform ${ |
| 69 | + expanded === answer.id ? "rotate-180" : "" |
| 70 | + }`} |
| 71 | + fill="none" |
| 72 | + viewBox="0 0 24 24" |
| 73 | + strokeWidth={2} |
| 74 | + stroke="currentColor" |
| 75 | + > |
| 76 | + <path |
| 77 | + strokeLinecap="round" |
| 78 | + strokeLinejoin="round" |
| 79 | + d="m19.5 8.25-7.5 7.5-7.5-7.5" |
| 80 | + /> |
| 81 | + </svg> |
| 82 | + </div> |
| 83 | + </button> |
| 84 | + |
| 85 | + <AnimatePresence> |
| 86 | + {expanded === answer.id && ( |
| 87 | + <motion.div |
| 88 | + initial={{ height: 0, opacity: 0 }} |
| 89 | + animate={{ height: "auto", opacity: 1 }} |
| 90 | + exit={{ height: 0, opacity: 0 }} |
| 91 | + transition={{ duration: 0.2 }} |
| 92 | + className="overflow-hidden" |
| 93 | + > |
| 94 | + <div className="px-4 pb-3 border-t border-white/5 pt-3 space-y-2"> |
| 95 | + {answer.elderAnswer && ( |
| 96 | + <div> |
| 97 | + <span className="text-xs text-gray-500"> |
| 98 | + Elder's answer: |
| 99 | + </span> |
| 100 | + <p className="text-sm text-gray-300"> |
| 101 | + {answer.elderAnswer} |
| 102 | + </p> |
| 103 | + </div> |
| 104 | + )} |
| 105 | + {answer.correctAnswer && ( |
| 106 | + <div> |
| 107 | + <span className="text-xs text-gray-500"> |
| 108 | + Correct answer: |
| 109 | + </span> |
| 110 | + <p className="text-sm text-emerald-400"> |
| 111 | + {answer.correctAnswer} |
| 112 | + </p> |
| 113 | + </div> |
| 114 | + )} |
| 115 | + {answer.audioUrl && ( |
| 116 | + <audio |
| 117 | + controls |
| 118 | + src={answer.audioUrl} |
| 119 | + className="w-full h-8 mt-2" |
| 120 | + /> |
| 121 | + )} |
| 122 | + </div> |
| 123 | + </motion.div> |
| 124 | + )} |
| 125 | + </AnimatePresence> |
| 126 | + </div> |
| 127 | + ))} |
| 128 | + </div> |
| 129 | + ); |
| 130 | +} |
0 commit comments