's'
This commit is contained in:
@@ -67,12 +67,15 @@ function DatingPageInner() {
|
||||
profile: DatingProfile;
|
||||
conversationId?: string;
|
||||
} | null>(null);
|
||||
const [likingBackId, setLikingBackId] = useState<string | null>(null);
|
||||
const [mobilePanelOpen, setMobilePanelOpen] = useState(false);
|
||||
const [dragX, setDragX] = useState(0);
|
||||
const [isDragging, setIsDragging] = useState(false);
|
||||
const [isAnimatingOut, setIsAnimatingOut] = useState<"left" | "right" | null>(null);
|
||||
const startXRef = useRef(0);
|
||||
const dragXRef = useRef(0);
|
||||
const swipeLockRef = useRef(false);
|
||||
const lastSwipedRef = useRef<DatingProfile | null>(null);
|
||||
|
||||
const cityOptions = useMemo(
|
||||
() =>
|
||||
@@ -170,30 +173,40 @@ function DatingPageInner() {
|
||||
const advanceProfile = () => {
|
||||
window.setTimeout(() => {
|
||||
setCurrentIndex((index) => (hasMoreProfiles ? index + 1 : index));
|
||||
dragXRef.current = 0;
|
||||
setDragX(0);
|
||||
setIsAnimatingOut(null);
|
||||
swipeLockRef.current = false;
|
||||
}, 180);
|
||||
};
|
||||
|
||||
const performSwipe = async (action: "like" | "dislike") => {
|
||||
const performSwipe = async (action: "like" | "dislike" | "superlike") => {
|
||||
if (!currentProfile || swipeLockRef.current) return;
|
||||
if (!isLoggedIn) {
|
||||
setShowLoginPrompt(true);
|
||||
dragXRef.current = 0;
|
||||
setDragX(0);
|
||||
return;
|
||||
}
|
||||
if (!quota.vip && quota.remaining <= 0) {
|
||||
setShowQuotaPrompt(true);
|
||||
dragXRef.current = 0;
|
||||
setDragX(0);
|
||||
return;
|
||||
}
|
||||
if (action === "superlike" && !quota.vip && !isVip) {
|
||||
setShowQuotaPrompt(true);
|
||||
return;
|
||||
}
|
||||
swipeLockRef.current = true;
|
||||
setIsAnimatingOut(action === "like" ? "right" : "left");
|
||||
setDragX(action === "like" ? 260 : -260);
|
||||
setIsAnimatingOut(action === "dislike" ? "left" : "right");
|
||||
const animX = action === "dislike" ? -260 : 260;
|
||||
dragXRef.current = animX;
|
||||
setDragX(animX);
|
||||
try {
|
||||
if (!usingFallback) {
|
||||
const result = await saveSwipe(currentProfile.id, action, activeTab);
|
||||
lastSwipedRef.current = currentProfile;
|
||||
setCanUndo(true);
|
||||
if (result.matched) {
|
||||
setMatchCelebration({
|
||||
@@ -201,34 +214,42 @@ function DatingPageInner() {
|
||||
conversationId: result.match?.conversationId,
|
||||
});
|
||||
refreshSidePanels();
|
||||
} else if (action === "like") {
|
||||
} else if (action === "like" || action === "superlike") {
|
||||
refreshSidePanels();
|
||||
}
|
||||
refreshQuota();
|
||||
} else {
|
||||
setCanUndo(true);
|
||||
setCanUndo(false);
|
||||
}
|
||||
advanceProfile();
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : "";
|
||||
if (message.includes("滑动次数") || message.includes("升级会员")) {
|
||||
if (message.includes("滑动次数") || message.includes("升级会员") || message.includes("超级赞")) {
|
||||
setShowQuotaPrompt(true);
|
||||
} else {
|
||||
} else if (message.includes("完善加入资料") || message.includes("登录")) {
|
||||
setShowLoginPrompt(true);
|
||||
} else if (message) {
|
||||
setShowLoginPrompt(true);
|
||||
}
|
||||
swipeLockRef.current = false;
|
||||
setIsAnimatingOut(null);
|
||||
dragXRef.current = 0;
|
||||
setDragX(0);
|
||||
return;
|
||||
} finally {
|
||||
advanceProfile();
|
||||
}
|
||||
};
|
||||
|
||||
const handleUndo = async () => {
|
||||
if (!canUndo || currentIndex <= 0) return;
|
||||
const lastProfile = lastSwipedRef.current;
|
||||
if (!canUndo || !lastProfile) return;
|
||||
try {
|
||||
if (!usingFallback) await undoSwipe();
|
||||
setCurrentIndex((index) => Math.max(0, index - 1));
|
||||
setProfiles((prev) => {
|
||||
if (prev.some((profile) => profile.id === lastProfile.id)) return prev;
|
||||
const next = [...prev];
|
||||
next.splice(currentIndex, 0, lastProfile);
|
||||
return next;
|
||||
});
|
||||
lastSwipedRef.current = null;
|
||||
setCanUndo(false);
|
||||
refreshQuota();
|
||||
} catch {
|
||||
@@ -238,6 +259,7 @@ function DatingPageInner() {
|
||||
|
||||
const handleLike = () => performSwipe("like");
|
||||
const handleDislike = () => performSwipe("dislike");
|
||||
const handleSuperLike = () => performSwipe("superlike");
|
||||
|
||||
const beginDrag = (clientX: number) => {
|
||||
startXRef.current = clientX;
|
||||
@@ -246,20 +268,24 @@ function DatingPageInner() {
|
||||
|
||||
const moveDrag = (clientX: number) => {
|
||||
if (!isDragging) return;
|
||||
setDragX(Math.max(-180, Math.min(180, clientX - startXRef.current)));
|
||||
const next = Math.max(-180, Math.min(180, clientX - startXRef.current));
|
||||
dragXRef.current = next;
|
||||
setDragX(next);
|
||||
};
|
||||
|
||||
const endDrag = () => {
|
||||
if (!isDragging) return;
|
||||
setIsDragging(false);
|
||||
if (dragX > 90) {
|
||||
const dx = dragXRef.current;
|
||||
if (dx > 90) {
|
||||
handleLike();
|
||||
return;
|
||||
}
|
||||
if (dragX < -90) {
|
||||
if (dx < -90) {
|
||||
handleDislike();
|
||||
return;
|
||||
}
|
||||
dragXRef.current = 0;
|
||||
setDragX(0);
|
||||
};
|
||||
|
||||
@@ -269,6 +295,36 @@ function DatingPageInner() {
|
||||
setMobilePanelOpen(false);
|
||||
};
|
||||
|
||||
const handleLikeBack = async (profile: DatingProfile) => {
|
||||
if (!isLoggedIn) {
|
||||
setShowLoginPrompt(true);
|
||||
return;
|
||||
}
|
||||
if (usingFallback) {
|
||||
jumpToProfile(profile);
|
||||
return;
|
||||
}
|
||||
setLikingBackId(profile.id);
|
||||
try {
|
||||
const result = await saveSwipe(profile.id, "like", activeTab);
|
||||
if (result.matched) {
|
||||
setMatchCelebration({
|
||||
profile,
|
||||
conversationId: result.match?.conversationId,
|
||||
});
|
||||
}
|
||||
refreshSidePanels();
|
||||
refreshQuota();
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : "";
|
||||
if (message.includes("滑动次数") || message.includes("升级会员")) {
|
||||
setShowQuotaPrompt(true);
|
||||
}
|
||||
} finally {
|
||||
setLikingBackId(null);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[#fafafa] dark:bg-gray-950">
|
||||
<div className="border-b border-gray-100 bg-white/80 backdrop-blur dark:border-gray-800 dark:bg-gray-950/80">
|
||||
@@ -329,6 +385,8 @@ function DatingPageInner() {
|
||||
formatTime={formatTime}
|
||||
t={t}
|
||||
onSelectProfile={jumpToProfile}
|
||||
onLikeBack={handleLikeBack}
|
||||
likingBackId={likingBackId}
|
||||
/>
|
||||
</div>
|
||||
</aside>
|
||||
@@ -348,6 +406,8 @@ function DatingPageInner() {
|
||||
isAnimatingOut={isAnimatingOut}
|
||||
onLike={handleLike}
|
||||
onDislike={handleDislike}
|
||||
onSuperLike={handleSuperLike}
|
||||
showSuperLike={quota.vip || isVip}
|
||||
onBeginDrag={beginDrag}
|
||||
onMoveDrag={moveDrag}
|
||||
onEndDrag={endDrag}
|
||||
@@ -420,6 +480,8 @@ function DatingPageInner() {
|
||||
formatTime={formatTime}
|
||||
t={t}
|
||||
onSelectProfile={jumpToProfile}
|
||||
onLikeBack={handleLikeBack}
|
||||
likingBackId={likingBackId}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user