's'
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import { Link } from "@/i18n/navigation";
|
||||
import { mediaUrl } from "@/app/lib/media";
|
||||
import type { DatingProfile } from "../types";
|
||||
@@ -10,6 +11,8 @@ interface LikesPanelProps {
|
||||
formatTime: (value?: string) => string;
|
||||
t: (key: string) => string;
|
||||
onSelectProfile?: (profile: DatingProfile) => void;
|
||||
onLikeBack?: (profile: DatingProfile) => void;
|
||||
likingBackId?: string | null;
|
||||
}
|
||||
|
||||
function ProfileRow({
|
||||
@@ -17,11 +20,13 @@ function ProfileRow({
|
||||
timeLabel,
|
||||
badge,
|
||||
onSelect,
|
||||
action,
|
||||
}: {
|
||||
profile: DatingProfile;
|
||||
timeLabel: string;
|
||||
badge?: string;
|
||||
onSelect?: () => void;
|
||||
action?: ReactNode;
|
||||
}) {
|
||||
const className =
|
||||
"flex w-full items-center gap-3 rounded-xl border border-gray-100 bg-white p-3 text-left shadow-sm transition-shadow hover:shadow-md dark:border-gray-800 dark:bg-gray-900";
|
||||
@@ -41,9 +46,12 @@ function ProfileRow({
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<span className="flex-shrink-0 rounded-full bg-gray-50 px-2 py-1 text-[10px] text-gray-400 dark:bg-gray-800 dark:text-gray-500">
|
||||
{timeLabel}
|
||||
</span>
|
||||
<div className="flex flex-shrink-0 flex-col items-end gap-2">
|
||||
{action}
|
||||
<span className="rounded-full bg-gray-50 px-2 py-1 text-[10px] text-gray-400 dark:bg-gray-800 dark:text-gray-500">
|
||||
{timeLabel}
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
if (onSelect) {
|
||||
@@ -56,7 +64,15 @@ function ProfileRow({
|
||||
return <div className={className}>{content}</div>;
|
||||
}
|
||||
|
||||
export default function LikesPanel({ likes, mutual, formatTime, t, onSelectProfile }: LikesPanelProps) {
|
||||
export default function LikesPanel({
|
||||
likes,
|
||||
mutual,
|
||||
formatTime,
|
||||
t,
|
||||
onSelectProfile,
|
||||
onLikeBack,
|
||||
likingBackId,
|
||||
}: LikesPanelProps) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<section>
|
||||
@@ -77,6 +93,21 @@ export default function LikesPanel({ likes, mutual, formatTime, t, onSelectProfi
|
||||
profile={profile}
|
||||
timeLabel={formatTime(profile.likedAt)}
|
||||
onSelect={() => onSelectProfile?.(profile)}
|
||||
action={
|
||||
onLikeBack ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onLikeBack(profile);
|
||||
}}
|
||||
disabled={likingBackId === profile.id}
|
||||
className="rounded-full bg-[#ff4d4f] px-3 py-1 text-[11px] font-semibold text-white disabled:opacity-60"
|
||||
>
|
||||
{likingBackId === profile.id ? "..." : t("likeBack")}
|
||||
</button>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
|
||||
@@ -12,6 +12,8 @@ interface SwipeCardProps {
|
||||
isAnimatingOut: "left" | "right" | null;
|
||||
onLike: () => void;
|
||||
onDislike: () => void;
|
||||
onSuperLike?: () => void;
|
||||
showSuperLike?: boolean;
|
||||
onBeginDrag: (clientX: number) => void;
|
||||
onMoveDrag: (clientX: number) => void;
|
||||
onEndDrag: () => void;
|
||||
@@ -26,6 +28,8 @@ export default function SwipeCard({
|
||||
isAnimatingOut,
|
||||
onLike,
|
||||
onDislike,
|
||||
onSuperLike,
|
||||
showSuperLike = false,
|
||||
onBeginDrag,
|
||||
onMoveDrag,
|
||||
onEndDrag,
|
||||
@@ -76,17 +80,20 @@ export default function SwipeCard({
|
||||
<Link
|
||||
href={`/feedback?type=report&target=${encodeURIComponent(profile.id)}`}
|
||||
className="text-sm font-medium text-[#ff4d4f] hover:text-red-600"
|
||||
onPointerDown={(e) => e.stopPropagation()}
|
||||
>
|
||||
{t("report")}
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="mb-6 mt-12 flex justify-center">
|
||||
<img
|
||||
src={mediaUrl(profile.photo)}
|
||||
alt={profile.name}
|
||||
className="h-28 w-28 rounded-full border-4 border-white/50 object-cover shadow-lg"
|
||||
/>
|
||||
<Link href={`/members/${profile.id}`} onPointerDown={(e) => e.stopPropagation()}>
|
||||
<img
|
||||
src={mediaUrl(profile.photo)}
|
||||
alt={profile.name}
|
||||
className="h-28 w-28 rounded-full border-4 border-white/50 object-cover shadow-lg transition hover:scale-105"
|
||||
/>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="mb-4 text-center">
|
||||
@@ -114,11 +121,17 @@ export default function SwipeCard({
|
||||
|
||||
<p className="mb-8 px-2 text-center text-sm leading-relaxed text-white/95">{profile.bio}</p>
|
||||
|
||||
<div className="flex items-center justify-center gap-8">
|
||||
<div
|
||||
className={`flex items-center justify-center ${showSuperLike ? "gap-5" : "gap-8"}`}
|
||||
onPointerDown={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onDislike}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onDislike();
|
||||
}}
|
||||
className="flex h-16 w-16 items-center justify-center rounded-full bg-white text-[#ff4d4f] shadow-lg transition-all hover:scale-105 hover:bg-red-50 active:scale-95"
|
||||
aria-label={t("dislike")}
|
||||
>
|
||||
@@ -126,10 +139,29 @@ export default function SwipeCard({
|
||||
</button>
|
||||
<span className="text-xs font-medium text-white/80">{t("dislike")}</span>
|
||||
</div>
|
||||
{showSuperLike && onSuperLike ? (
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onSuperLike();
|
||||
}}
|
||||
className="flex h-14 w-14 items-center justify-center rounded-full bg-amber-400 text-white shadow-lg ring-2 ring-amber-200 transition-all hover:scale-105 hover:bg-amber-500 active:scale-95"
|
||||
aria-label={t("superlike")}
|
||||
>
|
||||
<span className="text-xl">⭐</span>
|
||||
</button>
|
||||
<span className="text-xs font-medium text-white/80">{t("superlike")}</span>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onLike}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onLike();
|
||||
}}
|
||||
className="flex h-16 w-16 items-center justify-center rounded-full bg-[#22c55e] text-white shadow-lg transition-all hover:scale-105 hover:bg-[#16a34a] active:scale-95"
|
||||
aria-label={t("like")}
|
||||
>
|
||||
|
||||
@@ -13,6 +13,8 @@ interface SwipeStackProps {
|
||||
isAnimatingOut: "left" | "right" | null;
|
||||
onLike: () => void;
|
||||
onDislike: () => void;
|
||||
onSuperLike?: () => void;
|
||||
showSuperLike?: boolean;
|
||||
onBeginDrag: (clientX: number) => void;
|
||||
onMoveDrag: (clientX: number) => void;
|
||||
onEndDrag: () => void;
|
||||
@@ -28,6 +30,8 @@ export default function SwipeStack({
|
||||
isAnimatingOut,
|
||||
onLike,
|
||||
onDislike,
|
||||
onSuperLike,
|
||||
showSuperLike,
|
||||
onBeginDrag,
|
||||
onMoveDrag,
|
||||
onEndDrag,
|
||||
@@ -59,6 +63,8 @@ export default function SwipeStack({
|
||||
isAnimatingOut={isAnimatingOut}
|
||||
onLike={onLike}
|
||||
onDislike={onDislike}
|
||||
onSuperLike={onSuperLike}
|
||||
showSuperLike={showSuperLike}
|
||||
onBeginDrag={onBeginDrag}
|
||||
onMoveDrag={onMoveDrag}
|
||||
onEndDrag={onEndDrag}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -45,10 +45,20 @@ export function filterFallbackProfiles(
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (advanced?.gender && advanced.gender !== "all" && profile.gender !== advanced.gender) {
|
||||
if (
|
||||
advanced?.gender &&
|
||||
advanced.gender !== "all" &&
|
||||
advanced.gender !== "不限" &&
|
||||
profile.gender !== advanced.gender
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (advanced?.single && advanced.single !== "all" && profile.single !== advanced.single) {
|
||||
if (
|
||||
advanced?.single &&
|
||||
advanced.single !== "all" &&
|
||||
advanced.single !== "不限" &&
|
||||
profile.single !== advanced.single
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -123,7 +133,7 @@ export async function fetchMutualMatches(): Promise<DatingProfile[]> {
|
||||
|
||||
export async function saveSwipe(
|
||||
profileId: string,
|
||||
action: "like" | "dislike",
|
||||
action: "like" | "dislike" | "superlike",
|
||||
intent: MatchIntent
|
||||
): Promise<SwipeResult> {
|
||||
return apiFetch<SwipeResult>("/api/matches/swipes", {
|
||||
|
||||
Reference in New Issue
Block a user