's'
This commit is contained in:
@@ -1,161 +1,238 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Link, useTranslation } from "@/i18n/navigation";
|
||||
import { Suspense, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Link, useLocale, useTranslation } from "@/i18n/navigation";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import Footer from "@/app/components/Footer";
|
||||
import { apiFetch } from "@/app/lib/api-client";
|
||||
import { mediaUrl } from "@/app/lib/media";
|
||||
import { avatarForIndex, avatarForName } from "@/app/data/avatars";
|
||||
import { cities } from "@/app/data/cities";
|
||||
import { fetchAuthMe } from "@/app/lib/api-client";
|
||||
import IntentTabs from "./components/IntentTabs";
|
||||
import CityFilter from "./components/CityFilter";
|
||||
import LikesPanel from "./components/LikesPanel";
|
||||
import SwipeStack from "./components/SwipeStack";
|
||||
import MatchModal from "./components/MatchModal";
|
||||
import AdvancedFilters from "./components/AdvancedFilters";
|
||||
import SwipeQuota from "./components/SwipeQuota";
|
||||
import { BADGE_KEYS } from "./constants";
|
||||
import type { DatingProfile, MatchIntent } from "./types";
|
||||
import type { MatchQuota } from "./utils";
|
||||
import {
|
||||
fetchCandidates,
|
||||
fetchLikes,
|
||||
fetchMutualMatches,
|
||||
fetchQuota,
|
||||
filterFallbackProfiles,
|
||||
formatTimeAgo,
|
||||
saveSwipe,
|
||||
undoSwipe,
|
||||
} from "./utils";
|
||||
|
||||
type TabType = "friends" | "dating" | "partner" | "roommate" | "cofounder" | "explore";
|
||||
|
||||
interface Profile {
|
||||
id: string;
|
||||
name: string;
|
||||
age: number;
|
||||
location: string;
|
||||
tags: string[];
|
||||
bio: string;
|
||||
gradient: string;
|
||||
initial: string;
|
||||
avatarColor: string;
|
||||
photo: string;
|
||||
function DatingSkeleton() {
|
||||
return (
|
||||
<div className="min-h-screen bg-[#fafafa] dark:bg-gray-950">
|
||||
<div className="mx-auto max-w-md animate-pulse px-4 py-16">
|
||||
<div className="h-[520px] rounded-2xl bg-gray-200 dark:bg-gray-800" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface MatchCard {
|
||||
id: string;
|
||||
name: string;
|
||||
location: string;
|
||||
timeAgo: string;
|
||||
initial: string;
|
||||
color: string;
|
||||
photo: string;
|
||||
}
|
||||
|
||||
interface ProfileRecord {
|
||||
id: string;
|
||||
name?: string;
|
||||
age?: number;
|
||||
location?: string;
|
||||
tags?: string[];
|
||||
bio?: string;
|
||||
photo?: string;
|
||||
}
|
||||
|
||||
const FALLBACK_PROFILES: Profile[] = [
|
||||
{ id: "1", name: "林晓雨", age: 28, location: "大理", tags: ["本科学历", "远程工作者", "数字游民", "咖啡爱好者"], bio: "数字游民三年,目前在云南大理远程做产品设计。喜欢爬山、摄影,周末常去洱海边发呆。", gradient: "from-rose-400 via-pink-400 to-fuchsia-400", initial: "林", avatarColor: "bg-rose-500", photo: avatarForIndex(0) },
|
||||
{ id: "2", name: "陈浩然", age: 32, location: "成都", tags: ["硕士学历", "独立开发者", "自由职业者", "素食主义"], bio: "在成都住了两年,做独立开发。喜欢冲浪和冥想,寻找志同道合的旅伴一起探索世界。", gradient: "from-amber-400 via-orange-400 to-red-400", initial: "陈", avatarColor: "bg-amber-500", photo: avatarForIndex(4) },
|
||||
{ id: "3", name: "王思琪", age: 26, location: "深圳", tags: ["本科学历", "内容创作者", "数字游民", "环保主义者"], bio: "自由撰稿人,在深圳写写画画。热爱瑜伽和冥想,相信慢生活才是真正的奢侈。", gradient: "from-emerald-400 via-teal-400 to-cyan-400", initial: "王", avatarColor: "bg-emerald-500", photo: avatarForIndex(2) },
|
||||
{ id: "4", name: "张明远", age: 30, location: "杭州", tags: ["MBA学历", "创业中", "自由职业者", "徒步爱好者"], bio: "正在杭州创业,做远程团队协作工具。周末喜欢去西湖徒步,偶尔品鉴龙井茶。", gradient: "from-violet-400 via-purple-400 to-indigo-400", initial: "张", avatarColor: "bg-violet-500", photo: avatarForIndex(28) },
|
||||
{ id: "5", name: "李雅婷", age: 27, location: "厦门", tags: ["本科学历", "UI设计师", "数字游民", "摄影爱好者"], bio: "在厦门远程做UI设计,业余时间探索闽南美食。喜欢用相机记录生活,寻找一起探店的朋友。", gradient: "from-rose-500 via-red-400 to-orange-500", initial: "李", avatarColor: "bg-rose-500", photo: avatarForIndex(12) },
|
||||
{ id: "6", name: "刘子轩", age: 33, location: "昆明", tags: ["博士学历", "数据科学家", "远程工作者", "户外爱好者"], bio: "在昆明远程工作,热爱户外运动。正在探索云南各地,希望认识更多志同道合的朋友。", gradient: "from-blue-400 via-indigo-400 to-violet-500", initial: "刘", avatarColor: "bg-blue-500", photo: avatarForIndex(10) },
|
||||
];
|
||||
|
||||
const FALLBACK_MATCHES: MatchCard[] = [
|
||||
{ id: "m1", name: "周雨桐", location: "杭州", timeAgo: "2天前", initial: "周", color: "bg-pink-400", photo: avatarForIndex(6) },
|
||||
{ id: "m2", name: "吴俊杰", location: "成都", timeAgo: "1周前", initial: "吴", color: "bg-amber-400", photo: avatarForIndex(30) },
|
||||
{ id: "m3", name: "郑诗涵", location: "上海", timeAgo: "3周前", initial: "郑", color: "bg-emerald-400", photo: avatarForIndex(15) },
|
||||
{ id: "m4", name: "孙宇航", location: "深圳", timeAgo: "1月前", initial: "孙", color: "bg-violet-400", photo: avatarForIndex(18) },
|
||||
{ id: "m5", name: "赵梦琪", location: "厦门", timeAgo: "1年前", initial: "赵", color: "bg-rose-400", photo: avatarForIndex(24) },
|
||||
];
|
||||
|
||||
const TAB_ORDER: TabType[] = ["friends", "dating", "partner", "roommate", "cofounder", "explore"];
|
||||
|
||||
const PROFILE_GRADIENTS = [
|
||||
"from-rose-400 via-pink-400 to-fuchsia-400",
|
||||
"from-amber-400 via-orange-400 to-red-400",
|
||||
"from-emerald-400 via-teal-400 to-cyan-400",
|
||||
"from-violet-400 via-purple-400 to-indigo-400",
|
||||
"from-blue-400 via-indigo-400 to-violet-500",
|
||||
];
|
||||
|
||||
function mapProfile(record: ProfileRecord, index: number): Profile {
|
||||
const name = record.name || "数字游民";
|
||||
const initial = name.slice(0, 1);
|
||||
return {
|
||||
id: record.id,
|
||||
name,
|
||||
age: Number(record.age || 28 + index),
|
||||
location: record.location || "远程",
|
||||
tags: Array.isArray(record.tags) ? record.tags : ["数字游民", "远程工作者"],
|
||||
bio: record.bio || "正在完善个人资料,期待结识同城和同路的远程工作伙伴。",
|
||||
gradient: PROFILE_GRADIENTS[index % PROFILE_GRADIENTS.length],
|
||||
initial,
|
||||
avatarColor: "bg-[#ff4d4f]",
|
||||
photo: record.photo || avatarForName(name),
|
||||
};
|
||||
}
|
||||
|
||||
function toMatch(profile: Profile, index: number): MatchCard {
|
||||
return {
|
||||
id: `m-${profile.id}`,
|
||||
name: profile.name,
|
||||
location: profile.location,
|
||||
timeAgo: index < 2 ? "刚刚活跃" : "本周活跃",
|
||||
initial: profile.initial,
|
||||
color: profile.avatarColor,
|
||||
photo: profile.photo,
|
||||
};
|
||||
}
|
||||
|
||||
export default function DatingPage() {
|
||||
function DatingPageInner() {
|
||||
const { t } = useTranslation("match");
|
||||
const [activeTab, setActiveTab] = useState<TabType>("friends");
|
||||
const locale = useLocale();
|
||||
const searchParams = useSearchParams();
|
||||
const initialIntent = (searchParams.get("intent") as MatchIntent) || "friends";
|
||||
const initialCity = searchParams.get("city") || "all";
|
||||
|
||||
const [activeTab, setActiveTab] = useState<MatchIntent>(
|
||||
["friends", "dating", "partner", "roommate", "cofounder", "explore"].includes(initialIntent)
|
||||
? initialIntent
|
||||
: "friends"
|
||||
);
|
||||
const [cityFilter, setCityFilter] = useState(initialCity);
|
||||
const [profiles, setProfiles] = useState<DatingProfile[]>([]);
|
||||
const [likes, setLikes] = useState<DatingProfile[]>([]);
|
||||
const [mutual, setMutual] = useState<DatingProfile[]>([]);
|
||||
const [currentIndex, setCurrentIndex] = useState(0);
|
||||
const [profiles, setProfiles] = useState<Profile[]>(FALLBACK_PROFILES);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [usingFallback, setUsingFallback] = useState(false);
|
||||
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
||||
const [isVip, setIsVip] = useState(false);
|
||||
const [quota, setQuota] = useState<MatchQuota>({ vip: false, limit: 25, used: 0, remaining: 25 });
|
||||
const [advancedFilters, setAdvancedFilters] = useState({ gender: "all", single: "all" });
|
||||
const [showLoginPrompt, setShowLoginPrompt] = useState(false);
|
||||
const [showQuotaPrompt, setShowQuotaPrompt] = useState(false);
|
||||
const [canUndo, setCanUndo] = useState(false);
|
||||
const [matchCelebration, setMatchCelebration] = useState<DatingProfile | 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 swipeLockRef = useRef(false);
|
||||
|
||||
const cityOptions = useMemo(
|
||||
() =>
|
||||
cities.map((city) => ({
|
||||
slug: city.slug || city.name,
|
||||
name: city.name,
|
||||
nameEn: city.nameEn,
|
||||
})),
|
||||
[]
|
||||
);
|
||||
|
||||
const refreshSidePanels = useCallback(async () => {
|
||||
if (!isLoggedIn) {
|
||||
setLikes([]);
|
||||
setMutual([]);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const [likesData, mutualData] = await Promise.all([fetchLikes(), fetchMutualMatches()]);
|
||||
setLikes(likesData);
|
||||
setMutual(mutualData);
|
||||
} catch {
|
||||
setLikes([]);
|
||||
setMutual([]);
|
||||
}
|
||||
}, [isLoggedIn]);
|
||||
|
||||
const refreshQuota = useCallback(async () => {
|
||||
if (!isLoggedIn) return;
|
||||
try {
|
||||
const data = await fetchQuota();
|
||||
setQuota(data);
|
||||
setIsVip(data.vip);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}, [isLoggedIn]);
|
||||
|
||||
const loadCandidates = useCallback(
|
||||
async (intent: MatchIntent, city: string, advanced = advancedFilters) => {
|
||||
setLoading(true);
|
||||
setCurrentIndex(0);
|
||||
setCanUndo(false);
|
||||
try {
|
||||
const items = await fetchCandidates(intent, city, advanced);
|
||||
if (items.length) {
|
||||
setProfiles(items);
|
||||
setUsingFallback(false);
|
||||
} else {
|
||||
const fallback = filterFallbackProfiles(intent, city, advanced);
|
||||
setProfiles(fallback);
|
||||
setUsingFallback(true);
|
||||
}
|
||||
} catch {
|
||||
const fallback = filterFallbackProfiles(intent, city, advanced);
|
||||
setProfiles(fallback);
|
||||
setUsingFallback(true);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[advancedFilters]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
apiFetch<{ items: ProfileRecord[] }>("/api/profiles")
|
||||
.then((data) => {
|
||||
if (data.items?.length) {
|
||||
setProfiles(data.items.map(mapProfile));
|
||||
setCurrentIndex(0);
|
||||
}
|
||||
})
|
||||
.catch(() => setProfiles(FALLBACK_PROFILES));
|
||||
fetchAuthMe().then((data) => setIsLoggedIn(Boolean(data?.user?.id)));
|
||||
}, []);
|
||||
|
||||
const matches = useMemo(
|
||||
() => (profiles.length ? profiles.slice(0, 5).map(toMatch) : FALLBACK_MATCHES),
|
||||
[profiles]
|
||||
);
|
||||
const currentProfile = profiles[currentIndex] || profiles[0] || FALLBACK_PROFILES[0];
|
||||
useEffect(() => {
|
||||
if (isLoggedIn) refreshQuota();
|
||||
}, [isLoggedIn, refreshQuota]);
|
||||
|
||||
useEffect(() => {
|
||||
loadCandidates(activeTab, cityFilter, advancedFilters);
|
||||
}, [activeTab, cityFilter, advancedFilters, loadCandidates]);
|
||||
|
||||
useEffect(() => {
|
||||
refreshSidePanels();
|
||||
}, [refreshSidePanels]);
|
||||
|
||||
useEffect(() => {
|
||||
const params = new URLSearchParams();
|
||||
params.set("intent", activeTab);
|
||||
if (cityFilter && cityFilter !== "all") params.set("city", cityFilter);
|
||||
const next = `/dating?${params.toString()}`;
|
||||
window.history.replaceState(null, "", next);
|
||||
}, [activeTab, cityFilter]);
|
||||
|
||||
const currentProfile = profiles[currentIndex];
|
||||
const nextProfile = profiles[currentIndex + 1];
|
||||
const hasMoreProfiles = currentIndex < profiles.length - 1;
|
||||
const badgeText = t(BADGE_KEYS[activeTab]);
|
||||
const formatTime = (value?: string) => formatTimeAgo(value, locale);
|
||||
|
||||
const saveSwipe = (action: "like" | "dislike") => {
|
||||
if (!currentProfile) return;
|
||||
apiFetch("/api/matches/swipes", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ profileId: currentProfile.id, action }),
|
||||
}).catch(() => {});
|
||||
};
|
||||
|
||||
const nextProfile = () => {
|
||||
const advanceProfile = () => {
|
||||
window.setTimeout(() => {
|
||||
setCurrentIndex((i) => (hasMoreProfiles ? i + 1 : 0));
|
||||
setCurrentIndex((index) => (hasMoreProfiles ? index + 1 : index));
|
||||
setDragX(0);
|
||||
setIsAnimatingOut(null);
|
||||
}, 160);
|
||||
swipeLockRef.current = false;
|
||||
}, 180);
|
||||
};
|
||||
|
||||
const handleLike = () => {
|
||||
saveSwipe("like");
|
||||
setIsAnimatingOut("right");
|
||||
setDragX(260);
|
||||
nextProfile();
|
||||
const performSwipe = async (action: "like" | "dislike") => {
|
||||
if (!currentProfile || swipeLockRef.current) return;
|
||||
if (!isLoggedIn) {
|
||||
setShowLoginPrompt(true);
|
||||
setDragX(0);
|
||||
return;
|
||||
}
|
||||
if (!quota.vip && quota.remaining <= 0) {
|
||||
setShowQuotaPrompt(true);
|
||||
setDragX(0);
|
||||
return;
|
||||
}
|
||||
swipeLockRef.current = true;
|
||||
setIsAnimatingOut(action === "like" ? "right" : "left");
|
||||
setDragX(action === "like" ? 260 : -260);
|
||||
try {
|
||||
if (!usingFallback) {
|
||||
const result = await saveSwipe(currentProfile.id, action, activeTab);
|
||||
setCanUndo(true);
|
||||
if (result.matched) {
|
||||
setMatchCelebration(currentProfile);
|
||||
refreshSidePanels();
|
||||
} else if (action === "like") {
|
||||
refreshSidePanels();
|
||||
}
|
||||
refreshQuota();
|
||||
} else {
|
||||
setCanUndo(true);
|
||||
}
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : "";
|
||||
if (message.includes("滑动次数") || message.includes("升级会员")) {
|
||||
setShowQuotaPrompt(true);
|
||||
} else {
|
||||
setShowLoginPrompt(true);
|
||||
}
|
||||
swipeLockRef.current = false;
|
||||
setIsAnimatingOut(null);
|
||||
setDragX(0);
|
||||
return;
|
||||
} finally {
|
||||
advanceProfile();
|
||||
}
|
||||
};
|
||||
|
||||
const handleDislike = () => {
|
||||
saveSwipe("dislike");
|
||||
setIsAnimatingOut("left");
|
||||
setDragX(-260);
|
||||
nextProfile();
|
||||
const handleUndo = async () => {
|
||||
if (!canUndo || currentIndex <= 0) return;
|
||||
try {
|
||||
if (!usingFallback) await undoSwipe();
|
||||
setCurrentIndex((index) => Math.max(0, index - 1));
|
||||
setCanUndo(false);
|
||||
refreshQuota();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
};
|
||||
|
||||
const handleLike = () => performSwipe("like");
|
||||
const handleDislike = () => performSwipe("dislike");
|
||||
|
||||
const beginDrag = (clientX: number) => {
|
||||
startXRef.current = clientX;
|
||||
setIsDragging(true);
|
||||
@@ -180,130 +257,226 @@ export default function DatingPage() {
|
||||
setDragX(0);
|
||||
};
|
||||
|
||||
const badgeMap: Record<TabType, string> = {
|
||||
friends: t("badgeFriends"),
|
||||
dating: t("badgeDating"),
|
||||
partner: t("badgePartner"),
|
||||
roommate: t("badgeRoommate"),
|
||||
cofounder: t("badgeCofounder"),
|
||||
explore: t("badgeExplore"),
|
||||
const jumpToProfile = (profile: DatingProfile) => {
|
||||
const index = profiles.findIndex((item) => item.id === profile.id);
|
||||
if (index >= 0) setCurrentIndex(index);
|
||||
setMobilePanelOpen(false);
|
||||
};
|
||||
const badgeText = badgeMap[activeTab];
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[#fafafa] dark:bg-gray-950">
|
||||
<div className="flex justify-center pt-6 pb-4 px-4">
|
||||
<div className="flex flex-wrap justify-center gap-2 max-w-2xl">
|
||||
{TAB_ORDER.map((tab) => (
|
||||
<div className="border-b border-gray-100 bg-white/80 backdrop-blur dark:border-gray-800 dark:bg-gray-950/80">
|
||||
<div className="mx-auto flex max-w-7xl items-center justify-between px-4 py-4">
|
||||
<div>
|
||||
<h1 className="text-lg font-bold text-gray-900 dark:text-gray-100">{t("heroTitle")}</h1>
|
||||
<p className="text-xs text-gray-500 dark:text-gray-400">{t("heroSubtitle")}</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
key={tab}
|
||||
onClick={() => setActiveTab(tab)}
|
||||
className={`px-4 py-2 rounded-full text-xs sm:text-sm font-medium transition-all duration-200 ${
|
||||
activeTab === tab
|
||||
? "bg-[#ff4d4f] text-white shadow-sm"
|
||||
: "bg-white dark:bg-gray-900 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 border border-gray-100 dark:border-gray-800"
|
||||
}`}
|
||||
type="button"
|
||||
onClick={() => setMobilePanelOpen(true)}
|
||||
className="rounded-full border border-gray-200 px-3 py-1.5 text-xs font-semibold text-gray-700 md:hidden dark:border-gray-700 dark:text-gray-200"
|
||||
>
|
||||
{t(tab)}
|
||||
{t("mobilePanel")} {likes.length + mutual.length > 0 ? `(${likes.length + mutual.length})` : ""}
|
||||
</button>
|
||||
))}
|
||||
<Link
|
||||
href="/join"
|
||||
className="rounded-full bg-[#ff4d4f] px-3 py-1.5 text-xs font-semibold text-white transition hover:bg-red-600"
|
||||
>
|
||||
{t("editProfile")}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col md:flex-row gap-6 max-w-7xl mx-auto px-4 pb-12">
|
||||
<aside className="hidden md:block w-72 flex-shrink-0">
|
||||
<IntentTabs activeTab={activeTab} onChange={setActiveTab} t={t} />
|
||||
<CityFilter value={cityFilter} onChange={setCityFilter} cities={cityOptions} locale={locale} t={t} />
|
||||
<AdvancedFilters
|
||||
value={advancedFilters}
|
||||
onChange={setAdvancedFilters}
|
||||
isVip={isVip}
|
||||
t={t}
|
||||
/>
|
||||
{isLoggedIn ? <SwipeQuota vip={quota.vip} used={quota.used} limit={quota.limit} remaining={quota.remaining} t={t} /> : null}
|
||||
|
||||
{!isLoggedIn ? (
|
||||
<div className="mx-auto mb-4 max-w-md px-4">
|
||||
<div className="rounded-2xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900 dark:border-amber-900/40 dark:bg-amber-950/30 dark:text-amber-100">
|
||||
{t("loginHint")}{" "}
|
||||
<Link href="/join" className="font-semibold underline">
|
||||
{t("loginAction")}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{usingFallback ? (
|
||||
<p className="mx-auto mb-3 max-w-md px-4 text-center text-xs text-gray-400">{t("fallbackHint")}</p>
|
||||
) : null}
|
||||
|
||||
<div className="mx-auto flex max-w-7xl flex-col gap-6 px-4 pb-12 md:flex-row">
|
||||
<aside className="hidden w-72 flex-shrink-0 md:block">
|
||||
<div className="sticky top-24">
|
||||
<h2 className="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-1">{t("title")} 💕</h2>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400 mb-4">{t("likedYou")}</p>
|
||||
<div className="space-y-3">
|
||||
{matches.map((match) => (
|
||||
<div key={match.id} className="flex items-center gap-3 p-3 rounded-xl bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-800 shadow-sm hover:shadow-md transition-shadow cursor-pointer">
|
||||
<img src={mediaUrl(match.photo)} alt={match.name} className="w-12 h-12 rounded-full object-cover shadow-sm flex-shrink-0" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="font-medium text-gray-900 dark:text-gray-100 truncate">{match.name}</p>
|
||||
<p className="text-xs text-gray-500 dark:text-gray-400 truncate">{match.location}</p>
|
||||
</div>
|
||||
<span className="text-xs text-gray-400 dark:text-gray-500 bg-gray-50 dark:bg-gray-800 px-2 py-1 rounded-full flex-shrink-0">{match.timeAgo}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<LikesPanel
|
||||
likes={likes}
|
||||
mutual={mutual}
|
||||
formatTime={formatTime}
|
||||
t={t}
|
||||
onSelectProfile={jumpToProfile}
|
||||
/>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<main className="flex-1 min-w-0 flex flex-col items-center">
|
||||
<div className="w-full max-w-md mx-auto">
|
||||
<div
|
||||
className={`relative rounded-2xl overflow-hidden bg-gradient-to-br ${currentProfile.gradient} p-8 pb-6 shadow-xl border border-white/20 touch-pan-y select-none ${isDragging ? "cursor-grabbing" : "cursor-grab"} transition-transform`}
|
||||
style={{
|
||||
transform: `translateX(${isAnimatingOut === "right" ? 420 : isAnimatingOut === "left" ? -420 : dragX}px) rotate(${dragX / 18}deg)`,
|
||||
opacity: isAnimatingOut ? 0.25 : 1,
|
||||
transitionDuration: isDragging ? "0ms" : "180ms",
|
||||
}}
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "ArrowRight") handleLike();
|
||||
if (e.key === "ArrowLeft") handleDislike();
|
||||
}}
|
||||
onPointerDown={(e) => {
|
||||
e.currentTarget.setPointerCapture(e.pointerId);
|
||||
beginDrag(e.clientX);
|
||||
}}
|
||||
onPointerMove={(e) => moveDrag(e.clientX)}
|
||||
onPointerUp={endDrag}
|
||||
onPointerCancel={endDrag}
|
||||
>
|
||||
<div className={`pointer-events-none absolute left-5 top-5 rounded-full border-2 border-white/80 px-4 py-2 text-sm font-bold text-white transition-opacity ${dragX > 45 ? "opacity-100" : "opacity-0"}`}>
|
||||
喜欢
|
||||
</div>
|
||||
<div className={`pointer-events-none absolute right-5 top-5 rounded-full border-2 border-white/80 px-4 py-2 text-sm font-bold text-white transition-opacity ${dragX < -45 ? "opacity-100" : "opacity-0"}`}>
|
||||
跳过
|
||||
</div>
|
||||
<div className="absolute top-4 right-4 flex flex-col items-end gap-1">
|
||||
<span className="px-3 py-1.5 rounded-full bg-white/90 text-gray-800 text-xs font-medium backdrop-blur-sm">{badgeText}</span>
|
||||
<Link
|
||||
href={`/feedback?type=report&target=${encodeURIComponent(currentProfile.id)}`}
|
||||
className="text-[#ff4d4f] hover:text-red-600 text-sm font-medium"
|
||||
>
|
||||
{t("report")}
|
||||
</Link>
|
||||
</div>
|
||||
<div className="flex justify-center mt-12 mb-6">
|
||||
<img src={mediaUrl(currentProfile.photo)} alt={currentProfile.name} className="w-28 h-28 rounded-full shadow-lg border-4 border-white/50 object-cover" />
|
||||
</div>
|
||||
<div className="text-center mb-4">
|
||||
<h3 className="text-xl font-bold text-white drop-shadow-sm">{currentProfile.name},{currentProfile.age}</h3>
|
||||
<p className="text-white/90 text-sm mt-1">📍 {currentProfile.location}</p>
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<p className="text-white/90 text-xs font-medium mb-2">{t("matchTags")}:</p>
|
||||
<div className="flex flex-wrap gap-2 justify-center">
|
||||
{currentProfile.tags.map((tag) => (
|
||||
<span key={tag} className="px-3 py-1 rounded-full bg-white/80 text-gray-800 text-xs font-medium">{tag}</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-white/95 text-sm leading-relaxed text-center mb-8 px-2">{currentProfile.bio}</p>
|
||||
<div className="flex items-center justify-center gap-8">
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<button onClick={handleDislike} className="w-16 h-16 rounded-full bg-white shadow-lg flex items-center justify-center text-[#ff4d4f] hover:bg-red-50 hover:scale-105 active:scale-95 transition-all" aria-label={t("dislike")}>
|
||||
<span className="text-2xl">✕</span>
|
||||
<main className="flex min-w-0 flex-1 flex-col items-center">
|
||||
<div className="w-full max-w-md">
|
||||
{loading ? (
|
||||
<div className="h-[520px] animate-pulse rounded-2xl bg-gray-200 dark:bg-gray-800" />
|
||||
) : currentProfile ? (
|
||||
<>
|
||||
<SwipeStack
|
||||
current={currentProfile}
|
||||
next={nextProfile}
|
||||
badgeText={badgeText}
|
||||
dragX={dragX}
|
||||
isDragging={isDragging}
|
||||
isAnimatingOut={isAnimatingOut}
|
||||
onLike={handleLike}
|
||||
onDislike={handleDislike}
|
||||
onBeginDrag={beginDrag}
|
||||
onMoveDrag={moveDrag}
|
||||
onEndDrag={endDrag}
|
||||
t={t}
|
||||
/>
|
||||
<div className="mt-4 flex items-center justify-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleUndo}
|
||||
disabled={!canUndo || currentIndex <= 0}
|
||||
className="rounded-full border border-gray-200 px-4 py-2 text-xs font-semibold text-gray-600 transition enabled:hover:bg-gray-50 disabled:opacity-40 dark:border-gray-700 dark:text-gray-300"
|
||||
>
|
||||
↩ {t("undo")}
|
||||
</button>
|
||||
<span className="text-xs text-white/80 font-medium">{t("dislike")}</span>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400">
|
||||
{currentIndex + 1} / {profiles.length}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<button onClick={handleLike} className="w-16 h-16 rounded-full bg-[#22c55e] shadow-lg flex items-center justify-center text-white hover:bg-[#16a34a] hover:scale-105 active:scale-95 transition-all" aria-label={t("like")}>
|
||||
<span className="text-2xl">💚</span>
|
||||
<p className="mt-1 text-center text-xs text-gray-400 dark:text-gray-500">{t("keyboardHint")}</p>
|
||||
</>
|
||||
) : (
|
||||
<div className="rounded-2xl border border-dashed border-gray-200 bg-white p-10 text-center dark:border-gray-700 dark:bg-gray-900">
|
||||
<div className="text-4xl">🌏</div>
|
||||
<h3 className="mt-4 text-lg font-semibold text-gray-900 dark:text-gray-100">{t("emptyTitle")}</h3>
|
||||
<p className="mt-2 text-sm text-gray-500 dark:text-gray-400">{t("emptySubtitle")}</p>
|
||||
<div className="mt-6 flex flex-wrap justify-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setCityFilter("all");
|
||||
setActiveTab("friends");
|
||||
}}
|
||||
className="rounded-full border border-gray-200 px-4 py-2 text-sm font-medium dark:border-gray-700"
|
||||
>
|
||||
{t("resetFilters")}
|
||||
</button>
|
||||
<span className="text-xs text-white/80 font-medium">{t("like")}</span>
|
||||
<Link
|
||||
href="/join"
|
||||
className="rounded-full bg-[#ff4d4f] px-4 py-2 text-sm font-semibold text-white"
|
||||
>
|
||||
{t("editProfile")}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-center text-sm text-gray-500 dark:text-gray-400 mt-4">{currentIndex + 1} / {profiles.length}</p>
|
||||
)}
|
||||
</div>
|
||||
</main>
|
||||
<div className="hidden lg:block w-72 flex-shrink-0" />
|
||||
|
||||
<div className="hidden w-72 flex-shrink-0 lg:block" />
|
||||
</div>
|
||||
|
||||
{mobilePanelOpen ? (
|
||||
<div className="fixed inset-0 z-40 md:hidden">
|
||||
<button
|
||||
type="button"
|
||||
aria-label={t("closePanel")}
|
||||
className="absolute inset-0 bg-black/40"
|
||||
onClick={() => setMobilePanelOpen(false)}
|
||||
/>
|
||||
<div className="absolute bottom-0 max-h-[80vh] w-full overflow-y-auto rounded-t-3xl bg-[#fafafa] p-4 dark:bg-gray-950">
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<h2 className="font-semibold text-gray-900 dark:text-gray-100">{t("mobilePanel")}</h2>
|
||||
<button type="button" onClick={() => setMobilePanelOpen(false)} className="text-sm text-gray-500">
|
||||
{t("closePanel")}
|
||||
</button>
|
||||
</div>
|
||||
<LikesPanel
|
||||
likes={likes}
|
||||
mutual={mutual}
|
||||
formatTime={formatTime}
|
||||
t={t}
|
||||
onSelectProfile={jumpToProfile}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{showQuotaPrompt ? (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
|
||||
<div className="w-full max-w-sm rounded-2xl bg-white p-6 dark:bg-gray-900">
|
||||
<h3 className="text-lg font-bold text-gray-900 dark:text-gray-100">{t("quotaExceededTitle")}</h3>
|
||||
<p className="mt-2 text-sm text-gray-500 dark:text-gray-400">{t("quotaExceededBody")}</p>
|
||||
<div className="mt-5 flex gap-3">
|
||||
<Link
|
||||
href="/pricing"
|
||||
className="flex-1 rounded-full bg-[#ff4d4f] px-4 py-2 text-center text-sm font-semibold text-white"
|
||||
>
|
||||
{t("upgradeVip")}
|
||||
</Link>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowQuotaPrompt(false)}
|
||||
className="flex-1 rounded-full border border-gray-200 px-4 py-2 text-sm font-semibold dark:border-gray-700"
|
||||
>
|
||||
{t("closePanel")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{showLoginPrompt ? (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
|
||||
<div className="w-full max-w-sm rounded-2xl bg-white p-6 dark:bg-gray-900">
|
||||
<h3 className="text-lg font-bold text-gray-900 dark:text-gray-100">{t("loginRequiredTitle")}</h3>
|
||||
<p className="mt-2 text-sm text-gray-500 dark:text-gray-400">{t("loginRequiredBody")}</p>
|
||||
<div className="mt-5 flex gap-3">
|
||||
<Link
|
||||
href="/join"
|
||||
className="flex-1 rounded-full bg-[#ff4d4f] px-4 py-2 text-center text-sm font-semibold text-white"
|
||||
>
|
||||
{t("loginAction")}
|
||||
</Link>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowLoginPrompt(false)}
|
||||
className="flex-1 rounded-full border border-gray-200 px-4 py-2 text-sm font-semibold dark:border-gray-700"
|
||||
>
|
||||
{t("closePanel")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<MatchModal profile={matchCelebration} onClose={() => setMatchCelebration(null)} t={t} />
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function DatingPage() {
|
||||
return (
|
||||
<Suspense fallback={<DatingSkeleton />}>
|
||||
<DatingPageInner />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user