import React, { useEffect, useState } from 'react'; import { createPortal } from 'react-dom'; import { Task, TaskPriority } from '../types'; interface TaskCompleteModalProps { task: Task; level: number; onClose: () => void; } const ENCOURAGEMENTS: Record = { high: [ '太棒了!你攻克了最难的一关!🔥', '出色的工作!高难度任务也难不倒你!💪', '了不起!挑战完成了,你是最强的!⭐', '征服高难度任务的感觉真好!继续保持!🎯', ], medium: [ '干得漂亮!稳步前进中!🚀', '出色的工作!继续保持这个节奏!✨', '又完成了一项!你正在不断进步!🌟', '很棒!一步一个脚印,离目标更近了!👏', ], low: [ '轻松搞定!积少成多!💧', '完成啦!每一个小任务都算数!🌱', '搞定!小胜利也是胜利!🎯', '又一步完成了!保持节奏!😊', ], }; const LEVEL_LABELS: Record = { 0: '阶段', 1: '任务', 2: '子任务', }; const EMOJIS_BY_LEVEL: Record = { 0: ['🏆', '🎊', '🎉', '🥇'], 1: ['⭐', '✨', '💫', '🌟'], 2: ['👍', '👏', '💪', '🎯'], }; function getEncouragement(priority: TaskPriority, level: number): string { const pool = ENCOURAGEMENTS[priority] || ENCOURAGEMENTS.medium; const idx = (priority.charCodeAt(0) + level) % pool.length; return pool[idx]; } const TaskCompleteModal: React.FC = ({ task, level, onClose }) => { const [visible, setVisible] = useState(false); useEffect(() => { requestAnimationFrame(() => setVisible(true)); const timer = setTimeout(() => handleClose(), 4000); return () => clearTimeout(timer); }, []); const handleClose = () => { setVisible(false); setTimeout(onClose, 300); }; const encouragement = getEncouragement(task.priority, level); const levelLabel = LEVEL_LABELS[level] || '任务'; const emojis = EMOJIS_BY_LEVEL[level] || EMOJIS_BY_LEVEL[2]; const mainEmoji = emojis[Math.floor(Math.random() * emojis.length)]; return createPortal(
e.stopPropagation()} > {/* Confetti strip */}
{['#f59e0b', '#ef4444', '#3b82f6', '#10b981', '#8b5cf6', '#ec4899', '#f97316'].map((c, i) => (
))}
{/* Emoji with bounce */}
{mainEmoji}
{/* Level badge */} {levelLabel}完成 {/* Task title */}

{task.title}

{/* Encouragement */}

{encouragement}

{/* Progress ring */}
✓ 已完成
{/* Close button */}
{/* Floating particles */}
{Array.from({ length: 12 }).map((_, i) => (
))}
, document.body ); }; export default TaskCompleteModal;