dramaling-vocab-learning/frontend/components/flashcards/LearningComplete.tsx

124 lines
3.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import { useRouter } from 'next/navigation';
interface LearningCompleteProps {
score: {
correct: number;
total: number;
};
mode: string;
onRestart?: () => void;
onBackToDashboard?: () => void;
}
export default function LearningComplete({
score,
mode,
onRestart,
onBackToDashboard
}: LearningCompleteProps) {
const router = useRouter();
const percentage = score.total > 0 ? Math.round((score.correct / score.total) * 100) : 0;
const getGradeEmoji = (percentage: number) => {
if (percentage >= 90) return '🏆';
if (percentage >= 80) return '🎉';
if (percentage >= 70) return '👍';
if (percentage >= 60) return '😊';
return '💪';
};
const getGradeMessage = (percentage: number) => {
if (percentage >= 90) return '太棒了!你是學習高手!';
if (percentage >= 80) return '做得很好!繼續保持!';
if (percentage >= 70) return '不錯的表現!';
if (percentage >= 60) return '還不錯,繼續努力!';
return '加油!多練習會更好的!';
};
const getModeDisplayName = (mode: string) => {
switch (mode) {
case 'flip': return '翻卡模式';
case 'quiz': return '選擇題模式';
case 'fill': return '填空題模式';
case 'listening': return '聽力測試模式';
case 'speaking': return '口說練習模式';
default: return '學習模式';
}
};
return (
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50">
<div className="bg-white rounded-2xl shadow-2xl max-w-md w-full p-8 text-center">
{/* Celebration Icon */}
<div className="text-6xl mb-4">
{getGradeEmoji(percentage)}
</div>
{/* Title */}
<h2 className="text-2xl font-bold text-gray-900 mb-2">
</h2>
{/* Mode */}
<div className="text-sm text-gray-600 mb-6">
{getModeDisplayName(mode)}
</div>
{/* Score Display */}
<div className="bg-gray-50 rounded-xl p-6 mb-6">
<div className="text-4xl font-bold text-blue-600 mb-2">
{percentage}%
</div>
<div className="text-gray-600 mb-3">
</div>
<div className="text-sm text-gray-500">
<span className="font-semibold text-green-600">{score.correct}</span>
<span className="font-semibold">{score.total}</span>
</div>
</div>
{/* Encouragement Message */}
<div className="text-gray-700 mb-8">
{getGradeMessage(percentage)}
</div>
{/* Action Buttons */}
<div className="space-y-3">
{onRestart && (
<button
onClick={onRestart}
className="w-full py-3 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 transition-colors"
>
</button>
)}
<button
onClick={() => {
onBackToDashboard?.();
router.push('/dashboard');
}}
className="w-full py-3 bg-gray-200 text-gray-700 rounded-lg font-medium hover:bg-gray-300 transition-colors"
>
</button>
<button
onClick={() => router.push('/flashcards')}
className="w-full py-3 border border-gray-300 text-gray-700 rounded-lg font-medium hover:bg-gray-50 transition-colors"
>
</button>
</div>
{/* Tips */}
<div className="mt-6 text-xs text-gray-500">
💡
</div>
</div>
</div>
);
}