fix: 刷新页面后恢复滑动进度,防止重复 swipe
服务端 GET room 返回 swipeCounts,前端据此恢复 currentIndex、 swipeHistory 和引导状态;swipe API 增加幂等性检查,跳过已滑过的卡片。
This commit is contained in:
@@ -13,6 +13,7 @@ interface SwipeDeckProps {
|
||||
restaurants: Restaurant[];
|
||||
roomId: string;
|
||||
userId: string;
|
||||
initialIndex: number;
|
||||
matchedRestaurantId: string | null;
|
||||
matchType: MatchType;
|
||||
matchLikes: number;
|
||||
@@ -25,6 +26,7 @@ export default function SwipeDeck({
|
||||
restaurants,
|
||||
roomId,
|
||||
userId,
|
||||
initialIndex,
|
||||
matchedRestaurantId,
|
||||
matchType,
|
||||
matchLikes,
|
||||
@@ -32,13 +34,15 @@ export default function SwipeDeck({
|
||||
userCount,
|
||||
onReset,
|
||||
}: SwipeDeckProps) {
|
||||
const [currentIndex, setCurrentIndex] = useState(0);
|
||||
const [currentIndex, setCurrentIndex] = useState(initialIndex);
|
||||
const [showMatch, setShowMatch] = useState(false);
|
||||
const [localMatchId, setLocalMatchId] = useState<string | null>(null);
|
||||
const [resetting, setResetting] = useState(false);
|
||||
const [bubble, setBubble] = useState("");
|
||||
const [guideVisible, setGuideVisible] = useState(true);
|
||||
const [swipeHistory, setSwipeHistory] = useState<string[]>([]);
|
||||
const [guideVisible, setGuideVisible] = useState(initialIndex === 0);
|
||||
const [swipeHistory, setSwipeHistory] = useState<string[]>(
|
||||
() => restaurants.slice(0, initialIndex).map((r) => r.id),
|
||||
);
|
||||
const swipeFnRef = useRef<((direction: SwipeDirection) => void) | null>(null);
|
||||
const swipingRef = useRef(false);
|
||||
const prevLikeCounts = useRef<Record<string, number>>({});
|
||||
|
||||
Reference in New Issue
Block a user