diff --git a/src/app/api/room/[id]/route.ts b/src/app/api/room/[id]/route.ts index c3b0fca..4e1c018 100644 --- a/src/app/api/room/[id]/route.ts +++ b/src/app/api/room/[id]/route.ts @@ -32,9 +32,15 @@ export async function GET( matchLikes = data.users.length; } else if (allFinished && data.restaurants.length > 0) { const best = findBestMatch(data.likes, data.restaurants); - match = best.id; - matchType = "best"; - matchLikes = best.likes; + if (best.likes > 0) { + match = best.id; + matchType = "best"; + matchLikes = best.likes; + } else { + match = best.id; + matchType = "no_match"; + matchLikes = 0; + } } const likeCounts: Record = {}; diff --git a/src/components/MatchResult.tsx b/src/components/MatchResult.tsx index f83fe8e..10da8d5 100644 --- a/src/components/MatchResult.tsx +++ b/src/components/MatchResult.tsx @@ -1,6 +1,7 @@ "use client"; import { motion } from "framer-motion"; +import { useRouter } from "next/navigation"; import { MapPin, Star, @@ -10,6 +11,8 @@ import { Clock, Trophy, RotateCcw, + SearchX, + Home, } from "lucide-react"; import { Restaurant, MatchType } from "@/types"; @@ -30,6 +33,77 @@ function buildNavUrl(restaurant: Restaurant): string { return `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(restaurant.name)}`; } +function NoMatchResult({ + onReset, + resetting, +}: { + onReset: () => Promise; + resetting: boolean; +}) { + const router = useRouter(); + + return ( + + + + + + + 都不太满意 + + + + 这一轮没有餐厅被选中,换个范围或菜系再试试? + + + + + + {resetting ? "重置中..." : "再来一轮"} + + + router.push("/")} + className="flex items-center justify-center gap-2 rounded-full bg-white/15 px-8 py-3 text-sm font-bold text-white backdrop-blur-sm transition-colors hover:bg-white/25" + whileTap={{ scale: 0.95 }} + > + + 换个条件重新搜 + + + + ); +} + export default function MatchResult({ restaurant, matchType, @@ -38,6 +112,10 @@ export default function MatchResult({ onReset, resetting, }: MatchResultProps) { + if (matchType === "no_match") { + return ; + } + const isUnanimous = matchType === "unanimous"; return ( diff --git a/src/types/index.ts b/src/types/index.ts index 626a4f5..de4d485 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -15,7 +15,7 @@ export interface Restaurant { export type SwipeDirection = "left" | "right"; -export type MatchType = "unanimous" | "best" | null; +export type MatchType = "unanimous" | "best" | "no_match" | null; export interface RoomStatus { roomId: string;