feat: 撤回滑动功能,按钮移至进度条旁

- 新增 POST /api/room/[id]/undo 端点,撤回 like 和 swipeCount
- 进度条右侧显示"↩ 撤回"按钮,可一直撤回到第一张
- ActionButtons 恢复干净的两按钮布局,避免误触
This commit is contained in:
2026-02-24 17:48:47 +08:00
parent 1b06f4fc0e
commit 48e74c03e6
2 changed files with 92 additions and 3 deletions
+57
View File
@@ -0,0 +1,57 @@
import { NextResponse } from "next/server";
import { atomicUpdateRoom } from "@/lib/store";
export async function POST(
req: Request,
{ params }: { params: Promise<{ id: string }> },
) {
const { id } = await params;
try {
const { userId, restaurantId } = await req.json();
if (!userId || restaurantId == null) {
return NextResponse.json(
{ error: "userId and restaurantId are required" },
{ status: 400 },
);
}
const rid = String(restaurantId);
const updated = await atomicUpdateRoom(id, (data) => {
if (data.likes[rid]) {
data.likes[rid] = data.likes[rid].filter((u) => u !== userId);
if (data.likes[rid].length === 0) {
delete data.likes[rid];
}
}
if (data.match === rid) {
data.match = null;
}
const count = data.swipeCounts[userId] ?? 0;
if (count > 0) {
data.swipeCounts[userId] = count - 1;
}
return data;
});
if (!updated) {
return NextResponse.json(
{ error: "房间不存在或已过期" },
{ status: 404 },
);
}
return NextResponse.json({ ok: true });
} catch (e) {
console.error("Failed to undo swipe:", e);
return NextResponse.json(
{ error: "撤回失败" },
{ status: 500 },
);
}
}