feat: 拆分"再来一轮"为 Top N 决赛和换一批餐厅两个选项
This commit is contained in:
@@ -2,13 +2,27 @@ import { NextResponse } from "next/server";
|
||||
import { atomicUpdateRoom } from "@/lib/store";
|
||||
|
||||
export async function POST(
|
||||
_req: Request,
|
||||
req: Request,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const { id } = await params;
|
||||
|
||||
let restaurantIds: string[] | undefined;
|
||||
try {
|
||||
const body = await req.json().catch(() => null);
|
||||
if (body?.restaurantIds && Array.isArray(body.restaurantIds)) {
|
||||
restaurantIds = body.restaurantIds;
|
||||
}
|
||||
} catch {
|
||||
// No body or invalid JSON — plain reset
|
||||
}
|
||||
|
||||
try {
|
||||
const updated = await atomicUpdateRoom(id, (data) => {
|
||||
if (restaurantIds && restaurantIds.length > 0) {
|
||||
const idSet = new Set(restaurantIds);
|
||||
data.restaurants = data.restaurants.filter((r) => idSet.has(r.id));
|
||||
}
|
||||
data.likes = {};
|
||||
data.swipeCounts = {};
|
||||
data.match = null;
|
||||
|
||||
@@ -34,6 +34,15 @@ export default function RoomPage() {
|
||||
await mutate();
|
||||
}, [roomId, mutate]);
|
||||
|
||||
const handleNarrow = useCallback(async (restaurantIds: string[]) => {
|
||||
await fetch(`/api/room/${roomId}/reset`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ restaurantIds }),
|
||||
});
|
||||
await mutate();
|
||||
}, [roomId, mutate]);
|
||||
|
||||
const initialIndex = swipeCounts[userId] ?? 0;
|
||||
const ready = joined && userId && restaurants.length > 0;
|
||||
|
||||
@@ -62,6 +71,7 @@ export default function RoomPage() {
|
||||
swipeCounts={swipeCounts}
|
||||
userCount={userCount}
|
||||
onReset={handleReset}
|
||||
onNarrow={handleNarrow}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user