feat: 拆分"再来一轮"为 Top N 决赛和换一批餐厅两个选项
This commit is contained in:
@@ -149,6 +149,7 @@ interface SwipeDeckProps {
|
||||
swipeCounts: Record<string, number>;
|
||||
userCount: number;
|
||||
onReset: () => Promise<void>;
|
||||
onNarrow: (restaurantIds: string[]) => Promise<void>;
|
||||
}
|
||||
|
||||
export default function SwipeDeck({
|
||||
@@ -164,6 +165,7 @@ export default function SwipeDeck({
|
||||
swipeCounts,
|
||||
userCount,
|
||||
onReset,
|
||||
onNarrow,
|
||||
}: SwipeDeckProps) {
|
||||
const [currentIndex, setCurrentIndex] = useState(initialIndex);
|
||||
const [showMatch, setShowMatch] = useState(false);
|
||||
@@ -280,19 +282,33 @@ export default function SwipeDeck({
|
||||
swipeFnRef.current = null;
|
||||
}, [swipeHistory, currentIndex, roomId, userId]);
|
||||
|
||||
const clearLocalState = useCallback(() => {
|
||||
setCurrentIndex(0);
|
||||
setShowMatch(false);
|
||||
setLocalMatchId(null);
|
||||
setSwipeHistory([]);
|
||||
prevLikeCounts.current = {};
|
||||
}, []);
|
||||
|
||||
const handleReset = useCallback(async () => {
|
||||
setResetting(true);
|
||||
try {
|
||||
await onReset();
|
||||
setCurrentIndex(0);
|
||||
setShowMatch(false);
|
||||
setLocalMatchId(null);
|
||||
setSwipeHistory([]);
|
||||
prevLikeCounts.current = {};
|
||||
clearLocalState();
|
||||
} finally {
|
||||
setResetting(false);
|
||||
}
|
||||
}, [onReset]);
|
||||
}, [onReset, clearLocalState]);
|
||||
|
||||
const handleNarrow = useCallback(async (restaurantIds: string[]) => {
|
||||
setResetting(true);
|
||||
try {
|
||||
await onNarrow(restaurantIds);
|
||||
clearLocalState();
|
||||
} finally {
|
||||
setResetting(false);
|
||||
}
|
||||
}, [onNarrow, clearLocalState]);
|
||||
|
||||
const allSwiped = currentIndex >= restaurants.length;
|
||||
const isDone = allSwiped || resolvedMatchId != null;
|
||||
@@ -404,6 +420,7 @@ export default function SwipeDeck({
|
||||
allRestaurants={restaurants}
|
||||
userCount={userCount}
|
||||
onReset={handleReset}
|
||||
onNarrow={handleNarrow}
|
||||
resetting={resetting}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user