feat: 全员一致时增加 confetti 粒子特效、庆祝音效和默契度文案

This commit is contained in:
2026-02-24 22:03:49 +08:00
parent 43d3ff0fa3
commit 801e922bb6
5 changed files with 159 additions and 11 deletions
+42 -5
View File
@@ -1,6 +1,6 @@
"use client";
import { useState, useCallback } from "react";
import { useState, useCallback, useEffect, useRef } from "react";
import { motion, AnimatePresence } from "framer-motion";
import { useRouter } from "next/navigation";
import {
@@ -18,8 +18,10 @@ import {
Swords,
RefreshCw,
Share2,
Zap,
} from "lucide-react";
import { Restaurant, MatchType, RunnerUp } from "@/types";
import { fireCelebration, playChime } from "@/lib/celebrate";
interface MatchResultProps {
restaurant: Restaurant;
@@ -173,20 +175,37 @@ export default function MatchResult({
const router = useRouter();
const [showRunnerUps, setShowRunnerUps] = useState(false);
const [toast, setToast] = useState("");
const celebratedRef = useRef(false);
const isUnanimous = matchType === "unanimous";
const showToast = useCallback((msg: string) => {
setToast(msg);
setTimeout(() => setToast(""), 2200);
}, []);
useEffect(() => {
if (isUnanimous && !celebratedRef.current) {
const timer = setTimeout(() => {
celebratedRef.current = true;
fireCelebration();
playChime();
}, 500);
return () => clearTimeout(timer);
}
}, [isUnanimous]);
const handleShare = useCallback(async () => {
const lines = [
`🎉 我们用 NoWhatever 选好了!`,
isUnanimous
? `🎉 默契度 100%${userCount} 人全员一致选了同一家!`
: `🎉 我们用 NoWhatever 选好了!`,
``,
`📍 ${restaurant.name}`,
restaurant.rating ? `${restaurant.rating}` : "",
restaurant.price && restaurant.price !== "未知" ? `💰 人均${restaurant.price}` : "",
restaurant.address ? `📮 ${restaurant.address}` : "",
``,
isUnanimous ? `✨ 这就是心有灵犀吧~` : "",
].filter(Boolean);
const text = lines.join("\n");
@@ -213,14 +232,12 @@ export default function MatchResult({
} catch {
showToast("复制失败,请手动复制");
}
}, [restaurant, showToast]);
}, [restaurant, showToast, isUnanimous, userCount]);
if (matchType === "no_match") {
return <NoMatchResult onReset={onReset} resetting={resetting} />;
}
const isUnanimous = matchType === "unanimous";
const runnerUpRestaurants = runnerUps
.map((ru) => {
const r = allRestaurants.find((rest) => rest.id === ru.id);
@@ -277,6 +294,26 @@ export default function MatchResult({
: `${matchLikes}/${userCount} 人想去这家`}
</motion.p>
{isUnanimous && (
<motion.div
className="mt-3 flex items-center gap-2 rounded-full bg-white/20 px-4 py-1.5 backdrop-blur-sm"
initial={{ scale: 0, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }}
transition={{
type: "spring",
stiffness: 300,
damping: 15,
delay: 0.55,
}}
>
<Zap size={14} className="fill-yellow-300 text-yellow-300" />
<span className="text-xs font-bold text-white">
100% · {userCount}
</span>
<Zap size={14} className="fill-yellow-300 text-yellow-300" />
</motion.div>
)}
<motion.div
className="mt-6 w-full overflow-hidden rounded-2xl bg-white shadow-2xl"
initial={{ y: 60, opacity: 0 }}