'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", {
|
||||
|
||||
268
app/[locale]/discuss/[id]/page.tsx
Normal file
268
app/[locale]/discuss/[id]/page.tsx
Normal file
@@ -0,0 +1,268 @@
|
||||
"use client";
|
||||
|
||||
import { FormEvent, useEffect, useState } from "react";
|
||||
import { Link, useLocale } from "@/i18n/navigation";
|
||||
import { useParams } from "next/navigation";
|
||||
import Footer from "@/app/components/Footer";
|
||||
import { fetchAuthMe } from "@/app/lib/api-client";
|
||||
import {
|
||||
fetchDiscussion,
|
||||
fetchDiscussionReplies,
|
||||
postDiscussionReply,
|
||||
toggleDiscussionLike,
|
||||
toggleDiscussionPin,
|
||||
type DiscussionReply,
|
||||
} from "@/app/lib/social";
|
||||
|
||||
export default function DiscussThreadPage() {
|
||||
const params = useParams();
|
||||
const discussionId = String(params?.id || "");
|
||||
const locale = useLocale();
|
||||
const [topic, setTopic] = useState<Record<string, unknown> | null>(null);
|
||||
const [replies, setReplies] = useState<DiscussionReply[]>([]);
|
||||
const [draft, setDraft] = useState("");
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [posting, setPosting] = useState(false);
|
||||
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
||||
const [currentUserId, setCurrentUserId] = useState("");
|
||||
const [liking, setLiking] = useState(false);
|
||||
const [pinning, setPinning] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
fetchAuthMe().then((data) => {
|
||||
const userId = String(data?.user?.id || "");
|
||||
setIsLoggedIn(Boolean(userId));
|
||||
setCurrentUserId(userId);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!discussionId) return;
|
||||
let cancelled = false;
|
||||
Promise.all([fetchDiscussion(discussionId), fetchDiscussionReplies(discussionId)])
|
||||
.then(([topicData, replyItems]) => {
|
||||
if (cancelled) return;
|
||||
setTopic(topicData.item);
|
||||
setReplies(replyItems);
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) setError(locale === "zh" ? "加载失败" : "Failed to load");
|
||||
})
|
||||
.finally(() => {
|
||||
if (!cancelled) setLoading(false);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [discussionId, locale]);
|
||||
|
||||
const handleLike = async () => {
|
||||
if (!isLoggedIn || !discussionId) return;
|
||||
setLiking(true);
|
||||
setError("");
|
||||
try {
|
||||
const result = await toggleDiscussionLike(discussionId);
|
||||
setTopic((current) =>
|
||||
current
|
||||
? {
|
||||
...current,
|
||||
likes: result.likes,
|
||||
likedByMe: result.liked,
|
||||
}
|
||||
: current
|
||||
);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : locale === "zh" ? "点赞失败" : "Like failed");
|
||||
} finally {
|
||||
setLiking(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handlePin = async () => {
|
||||
if (!isLoggedIn || !discussionId) return;
|
||||
setPinning(true);
|
||||
setError("");
|
||||
try {
|
||||
const result = await toggleDiscussionPin(discussionId);
|
||||
setTopic((current) =>
|
||||
current
|
||||
? {
|
||||
...current,
|
||||
pinned: result.pinned,
|
||||
}
|
||||
: current
|
||||
);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : locale === "zh" ? "置顶失败" : "Pin failed");
|
||||
} finally {
|
||||
setPinning(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = async (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
const body = draft.trim();
|
||||
if (!body || !discussionId) return;
|
||||
if (!isLoggedIn) {
|
||||
setError(locale === "zh" ? "请先登录后再回复" : "Please log in to reply");
|
||||
return;
|
||||
}
|
||||
setPosting(true);
|
||||
setError("");
|
||||
try {
|
||||
const reply = await postDiscussionReply(discussionId, body);
|
||||
setReplies((current) => [...current, reply]);
|
||||
setDraft("");
|
||||
setTopic((current) =>
|
||||
current ? { ...current, replies: Number(current.replies || 0) + 1 } : current
|
||||
);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : locale === "zh" ? "回复失败" : "Reply failed");
|
||||
} finally {
|
||||
setPosting(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="min-h-screen bg-[#fafafa] dark:bg-gray-950">
|
||||
<div className="mx-auto max-w-3xl animate-pulse px-4 py-10">
|
||||
<div className="h-40 rounded-2xl bg-gray-200 dark:bg-gray-800" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!topic) {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-[#fafafa] px-4 dark:bg-gray-950">
|
||||
<div className="text-center">
|
||||
<p className="text-gray-500 dark:text-gray-400">{error || (locale === "zh" ? "话题不存在" : "Topic not found")}</p>
|
||||
<Link href="/discuss" className="mt-4 inline-block text-[#ff4d4f]">
|
||||
{locale === "zh" ? "返回讨论区" : "Back to discussions"}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const tags = Array.isArray(topic.tags) ? topic.tags.map(String) : [];
|
||||
const likedByMe = Boolean(topic.likedByMe);
|
||||
const likes = Number(topic.likes || 0);
|
||||
const pinned = Boolean(topic.pinned);
|
||||
const isAuthor = Boolean(currentUserId && String(topic.authorUserId || "") === currentUserId);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[#fafafa] dark:bg-gray-950">
|
||||
<main className="mx-auto max-w-3xl px-4 py-8 sm:px-6">
|
||||
<Link href="/discuss" className="text-sm text-gray-500 hover:text-[#ff4d4f] dark:text-gray-400">
|
||||
← {locale === "zh" ? "返回讨论区" : "Back"}
|
||||
</Link>
|
||||
|
||||
<article className="mt-4 rounded-2xl border border-gray-100 bg-white p-6 shadow-sm dark:border-gray-800 dark:bg-gray-900">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{tags.map((tag) => (
|
||||
<span key={tag} className="rounded-full bg-red-50 px-2.5 py-0.5 text-xs text-[#ff4d4f] dark:bg-red-950/30">
|
||||
{tag}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<div className="mt-3 flex flex-wrap items-start justify-between gap-3">
|
||||
<h1 className="text-2xl font-bold text-gray-900 dark:text-gray-100">{String(topic.title || "")}</h1>
|
||||
{pinned ? (
|
||||
<span className="rounded-full bg-amber-50 px-2.5 py-1 text-xs font-semibold text-amber-700 dark:bg-amber-950/30 dark:text-amber-300">
|
||||
📌 {locale === "zh" ? "置顶" : "Pinned"}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<p className="mt-2 text-sm text-gray-500 dark:text-gray-400">
|
||||
{String(topic.author || "社区成员")}
|
||||
{topic.city ? ` · ${String(topic.city)}` : ""}
|
||||
{` · 👁 ${Number(topic.views || 0)} · 💬 ${Number(topic.replies || 0)}`}
|
||||
</p>
|
||||
<div className="mt-4 flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleLike}
|
||||
disabled={!isLoggedIn || liking}
|
||||
className={`inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-sm font-medium transition ${
|
||||
likedByMe
|
||||
? "bg-red-50 text-[#ff4d4f] dark:bg-red-950/30"
|
||||
: "bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700"
|
||||
} disabled:opacity-50`}
|
||||
>
|
||||
{likedByMe ? "❤️" : "🤍"} {likes}
|
||||
</button>
|
||||
{isAuthor ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handlePin}
|
||||
disabled={pinning}
|
||||
className={`inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-sm font-medium transition ${
|
||||
pinned
|
||||
? "bg-amber-50 text-amber-700 dark:bg-amber-950/30 dark:text-amber-300"
|
||||
: "bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700"
|
||||
} disabled:opacity-50`}
|
||||
>
|
||||
📌 {pinned ? (locale === "zh" ? "取消置顶" : "Unpin") : locale === "zh" ? "置顶话题" : "Pin topic"}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
{topic.excerpt ? (
|
||||
<p className="mt-4 whitespace-pre-wrap text-sm leading-7 text-gray-700 dark:text-gray-300">
|
||||
{String(topic.excerpt)}
|
||||
</p>
|
||||
) : null}
|
||||
</article>
|
||||
|
||||
<section className="mt-6 space-y-3">
|
||||
<h2 className="text-lg font-semibold text-gray-900 dark:text-gray-100">
|
||||
{locale === "zh" ? "回复" : "Replies"} ({replies.length})
|
||||
</h2>
|
||||
{replies.length ? (
|
||||
replies.map((reply) => (
|
||||
<div
|
||||
key={reply.id}
|
||||
className="rounded-xl border border-gray-100 bg-white p-4 dark:border-gray-800 dark:bg-gray-900"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="text-sm font-semibold text-gray-900 dark:text-gray-100">
|
||||
{reply.author || (locale === "zh" ? "成员" : "Member")}
|
||||
</span>
|
||||
<span className="text-xs text-gray-400">{reply.created ? new Date(reply.created).toLocaleString() : ""}</span>
|
||||
</div>
|
||||
<p className="mt-2 whitespace-pre-wrap text-sm leading-6 text-gray-700 dark:text-gray-300">{reply.body}</p>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<p className="rounded-xl border border-dashed border-gray-200 p-6 text-center text-sm text-gray-500 dark:border-gray-700 dark:text-gray-400">
|
||||
{locale === "zh" ? "还没有回复,来抢沙发吧" : "No replies yet"}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<form onSubmit={handleSubmit} className="mt-6 rounded-2xl border border-gray-100 bg-white p-4 dark:border-gray-800 dark:bg-gray-900">
|
||||
<textarea
|
||||
value={draft}
|
||||
onChange={(event) => setDraft(event.target.value)}
|
||||
rows={4}
|
||||
placeholder={locale === "zh" ? "写下你的经验、建议或提问..." : "Share your thoughts..."}
|
||||
className="w-full resize-none rounded-xl border border-gray-200 bg-white px-4 py-3 text-sm text-gray-900 focus:border-[#ff4d4f] focus:outline-none dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100"
|
||||
/>
|
||||
{error ? <p className="mt-2 text-sm text-red-500">{error}</p> : null}
|
||||
<div className="mt-3 flex justify-end">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={posting || !draft.trim()}
|
||||
className="rounded-full bg-[#ff4d4f] px-5 py-2 text-sm font-semibold text-white disabled:opacity-50"
|
||||
>
|
||||
{posting ? (locale === "zh" ? "发送中..." : "Posting...") : locale === "zh" ? "发表回复" : "Reply"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</main>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "@/i18n/navigation";
|
||||
import { Link, useTranslation } from "@/i18n/navigation";
|
||||
import Footer from "@/app/components/Footer";
|
||||
import { apiFetch } from "@/app/lib/api-client";
|
||||
import { apiFetch, fetchAuthMe } from "@/app/lib/api-client";
|
||||
import { toggleDiscussionLike } from "@/app/lib/social";
|
||||
import { mediaUrl } from "@/app/lib/media";
|
||||
import { avatarForIndex, avatarForName } from "@/app/data/avatars";
|
||||
|
||||
@@ -19,6 +20,7 @@ interface Topic {
|
||||
lastActive: string;
|
||||
pinned: boolean;
|
||||
excerpt?: string;
|
||||
likedByMe?: boolean;
|
||||
}
|
||||
|
||||
interface DiscussionRecord {
|
||||
@@ -30,6 +32,9 @@ interface DiscussionRecord {
|
||||
excerpt?: string;
|
||||
replies?: number;
|
||||
views?: number;
|
||||
likes?: number;
|
||||
pinned?: boolean;
|
||||
likedByMe?: boolean;
|
||||
created?: string;
|
||||
}
|
||||
|
||||
@@ -143,7 +148,7 @@ const CATEGORIES = [
|
||||
{ key: "目的地", zh: "目的地", en: "Destinations" },
|
||||
];
|
||||
|
||||
function mapDiscussion(topic: DiscussionRecord, index: number): Topic {
|
||||
function mapDiscussion(topic: DiscussionRecord): Topic {
|
||||
const author = topic.author || "NomadCNA";
|
||||
const tags = Array.isArray(topic.tags) ? topic.tags : [];
|
||||
return {
|
||||
@@ -153,11 +158,12 @@ function mapDiscussion(topic: DiscussionRecord, index: number): Topic {
|
||||
avatar: avatarForName(author),
|
||||
views: Number(topic.views || 0),
|
||||
replies: Number(topic.replies || 0),
|
||||
likes: Math.max(3, Math.round(Number(topic.views || 0) / 30) + Number(topic.replies || 0)),
|
||||
likes: Number(topic.likes || 0),
|
||||
category: tags[0] || topic.city || "资源分享",
|
||||
lastActive: topic.created ? new Date(topic.created).toLocaleDateString("zh-CN") : "刚刚",
|
||||
pinned: index < 2,
|
||||
pinned: Boolean(topic.pinned),
|
||||
excerpt: topic.excerpt,
|
||||
likedByMe: Boolean(topic.likedByMe),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -169,6 +175,12 @@ export default function DiscussPage() {
|
||||
const [showComposer, setShowComposer] = useState(false);
|
||||
const [posting, setPosting] = useState(false);
|
||||
const [draft, setDraft] = useState({ title: "", city: "", excerpt: "" });
|
||||
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
||||
const [likingId, setLikingId] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetchAuthMe().then((data) => setIsLoggedIn(Boolean(data?.user?.id)));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
apiFetch<{ items: DiscussionRecord[] }>("/api/discussions")
|
||||
@@ -180,6 +192,25 @@ export default function DiscussPage() {
|
||||
.catch(() => setTopics(FALLBACK_TOPICS));
|
||||
}, []);
|
||||
|
||||
const handleLike = async (topicId: string, event: React.MouseEvent) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (!isLoggedIn) return;
|
||||
setLikingId(topicId);
|
||||
try {
|
||||
const result = await toggleDiscussionLike(topicId);
|
||||
setTopics((current) =>
|
||||
current.map((topic) =>
|
||||
topic.id === topicId
|
||||
? { ...topic, likes: result.likes, likedByMe: result.liked }
|
||||
: topic
|
||||
)
|
||||
);
|
||||
} finally {
|
||||
setLikingId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const filteredTopics = useMemo(() => topics.filter((topic) => {
|
||||
const matchesCategory = activeCategory === "all" || topic.category === activeCategory;
|
||||
const matchesSearch = topic.title.toLowerCase().includes(searchQuery.toLowerCase());
|
||||
@@ -201,7 +232,7 @@ export default function DiscussPage() {
|
||||
excerpt: draft.excerpt.trim(),
|
||||
}),
|
||||
});
|
||||
setTopics((current) => [mapDiscussion(data.record, 0), ...current]);
|
||||
setTopics((current) => [mapDiscussion(data.record), ...current]);
|
||||
setDraft({ title: "", city: "", excerpt: "" });
|
||||
setShowComposer(false);
|
||||
} finally {
|
||||
@@ -292,9 +323,10 @@ export default function DiscussPage() {
|
||||
|
||||
<div className="space-y-3 sm:space-y-4">
|
||||
{filteredTopics.map((topic) => (
|
||||
<div
|
||||
<Link
|
||||
key={topic.id}
|
||||
className="bg-white dark:bg-gray-900 rounded-xl p-4 sm:p-5 shadow-sm border border-gray-100 dark:border-gray-800 hover:shadow-md transition-shadow cursor-pointer"
|
||||
href={`/discuss/${topic.id}`}
|
||||
className="block bg-white dark:bg-gray-900 rounded-xl p-4 sm:p-5 shadow-sm border border-gray-100 dark:border-gray-800 hover:shadow-md transition-shadow"
|
||||
>
|
||||
<div className="flex items-start gap-3 sm:gap-4">
|
||||
<img
|
||||
@@ -324,11 +356,20 @@ export default function DiscussPage() {
|
||||
<span className="hidden sm:inline">·</span>
|
||||
<span>👁 {topic.views}</span>
|
||||
<span>💬 {topic.replies}</span>
|
||||
<span>❤️ {topic.likes}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(event) => handleLike(topic.id, event)}
|
||||
disabled={likingId === topic.id}
|
||||
className={`inline-flex items-center gap-1 rounded-full px-2 py-0.5 transition ${
|
||||
topic.likedByMe ? "bg-red-50 text-[#ff4d4f] dark:bg-red-950/30" : "hover:bg-gray-100 dark:hover:bg-gray-800"
|
||||
}`}
|
||||
>
|
||||
{topic.likedByMe ? "❤️" : "🤍"} {topic.likes}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -73,21 +73,50 @@ export default function JoinPage() {
|
||||
const [isAlreadyRecorded, setIsAlreadyRecorded] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== "undefined" && new URLSearchParams(window.location.search).get("paid") === "1") {
|
||||
setSubmitted(true);
|
||||
return;
|
||||
}
|
||||
const checkExisting = async () => {
|
||||
try {
|
||||
const meData = await fetchAuthMe();
|
||||
if (!meData?.user) return;
|
||||
const statusData = await apiFetch<{ hasRecord?: boolean; isComplete?: boolean }>(
|
||||
"/api/join/status",
|
||||
{ cache: "no-store" }
|
||||
);
|
||||
const [statusData, profileData] = await Promise.all([
|
||||
apiFetch<{ hasRecord?: boolean; isComplete?: boolean }>("/api/join/status", {
|
||||
cache: "no-store",
|
||||
}),
|
||||
apiFetch<{
|
||||
profile?: {
|
||||
name?: string;
|
||||
gender?: string;
|
||||
single?: string;
|
||||
location?: string;
|
||||
citySlug?: string;
|
||||
bio?: string;
|
||||
photo?: string;
|
||||
lookingFor?: string[];
|
||||
tags?: string[];
|
||||
};
|
||||
}>("/api/matches/profile/me", { cache: "no-store" }),
|
||||
]);
|
||||
const profile = profileData?.profile;
|
||||
if (profile) {
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
nickname: profile.name || prev.nickname,
|
||||
gender: profile.gender || prev.gender,
|
||||
single: profile.single || prev.single,
|
||||
location: profile.location || prev.location,
|
||||
citySlug: profile.citySlug || prev.citySlug,
|
||||
intro: profile.bio || prev.intro,
|
||||
profession: profile.tags?.[0] || prev.profession,
|
||||
education: profile.tags?.[1] || prev.education,
|
||||
}));
|
||||
if (Array.isArray(profile.lookingFor) && profile.lookingFor.length > 0) {
|
||||
setLookingFor(profile.lookingFor);
|
||||
}
|
||||
if (profile.photo) {
|
||||
setMedia({ preview: profile.photo, url: profile.photo, type: "image" });
|
||||
}
|
||||
}
|
||||
if (statusData?.hasRecord && statusData?.isComplete) {
|
||||
setIsAlreadyRecorded(true);
|
||||
setSubmitted(true);
|
||||
}
|
||||
} catch {
|
||||
// Keep the form usable when the API proxy/backend is temporarily unavailable.
|
||||
@@ -219,6 +248,12 @@ export default function JoinPage() {
|
||||
<div className="absolute -right-10 -bottom-10 h-48 w-48 rounded-full bg-white/10 blur-2xl" />
|
||||
</div>
|
||||
|
||||
{isAlreadyRecorded && (
|
||||
<div className="mx-5 mt-4 rounded-xl border border-sky-100 bg-sky-50 px-4 py-3 text-sm text-sky-800 dark:border-sky-900/50 dark:bg-sky-950/40 dark:text-sky-200 sm:mx-8">
|
||||
你已提交过资料,可直接修改后保存更新,匹配与活动推荐会同步使用最新信息。
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="px-5 py-5 text-center sm:px-8 sm:py-7">
|
||||
<h1 className="text-xl font-bold text-slate-800 dark:text-slate-100 sm:text-2xl">
|
||||
🌍 数字游民社区报名
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { Locale } from "../context/LocaleContext";
|
||||
import { getThemeMessages } from "@/app/lib/theme-data";
|
||||
import RouteAwareNavbar from "../components/RouteAwareNavbar";
|
||||
import SetLangAttr from "../components/SetLangAttr";
|
||||
import DevDebugTools from "../components/DevDebugTools";
|
||||
|
||||
const LOCALES: Locale[] = ["zh", "en"];
|
||||
|
||||
@@ -34,9 +35,11 @@ export default async function LocaleLayout({
|
||||
|
||||
return (
|
||||
<LocaleProvider locale={locale as Locale} messages={messages}>
|
||||
<SetLangAttr />
|
||||
<RouteAwareNavbar />
|
||||
{children}
|
||||
<DevDebugTools>
|
||||
<SetLangAttr />
|
||||
<RouteAwareNavbar />
|
||||
{children}
|
||||
</DevDebugTools>
|
||||
</LocaleProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ export default function HostMeetupPage() {
|
||||
const locale = useLocale();
|
||||
const c = getCopy(locale);
|
||||
const [submitted, setSubmitted] = useState(false);
|
||||
const [submitError, setSubmitError] = useState<string | null>(null);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [form, setForm] = useState<HostMeetupForm>({
|
||||
mode: "offline",
|
||||
@@ -152,10 +153,12 @@ export default function HostMeetupPage() {
|
||||
const handleSubmit = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
setSubmitting(true);
|
||||
setSubmitError(null);
|
||||
try {
|
||||
const finalCity = isOnlineOnly && !form.city ? "线上" : form.city;
|
||||
const finalVenue = isOnlineOnly && !form.venue ? "MiroTalk 多人视频房" : form.venue;
|
||||
const finalAddress = isOnlineOnly && !form.address ? "线上活动" : form.address;
|
||||
const customRoom = normalizeMiroTalkRoom(form.mirotalkRoom);
|
||||
await apiFetch("/api/meetups", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
@@ -166,7 +169,6 @@ export default function HostMeetupPage() {
|
||||
venue: finalVenue,
|
||||
address: finalAddress,
|
||||
description: form.description,
|
||||
rsvpCount: 1,
|
||||
gradientFrom: city?.gradientFrom || (isOnlineMode ? "#0f766e" : "#ff4d4f"),
|
||||
gradientTo: city?.gradientTo || (isOnlineMode ? "#2563eb" : "#ff7a45"),
|
||||
attendees: [],
|
||||
@@ -177,13 +179,21 @@ export default function HostMeetupPage() {
|
||||
organizer: form.organizer.trim() || "NomadCNA",
|
||||
accessLevel: form.accessLevel,
|
||||
meetingProvider: isOnlineMode ? form.meetingProvider : "",
|
||||
mirotalkRoom: isOnlineMode ? roomToUse : "",
|
||||
mirotalkRoom: isOnlineMode && customRoom ? customRoom : "",
|
||||
meetingUrl: isOnlineMode ? form.meetingUrl.trim() : "",
|
||||
replayUrl: "",
|
||||
features: isOnlineMode ? form.features : [],
|
||||
}),
|
||||
});
|
||||
setSubmitted(true);
|
||||
} catch (err) {
|
||||
setSubmitError(
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: locale === "zh"
|
||||
? "提交失败,请稍后重试"
|
||||
: "Submission failed, please try again"
|
||||
);
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
@@ -479,6 +489,12 @@ export default function HostMeetupPage() {
|
||||
{c.pendingHint}
|
||||
</p>
|
||||
|
||||
{submitError && (
|
||||
<p className="rounded-lg border border-red-100 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-300">
|
||||
{submitError}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={submitting}
|
||||
|
||||
@@ -22,10 +22,33 @@ import {
|
||||
} from "@/app/lib/meetups";
|
||||
import { mediaUrl } from "@/app/lib/media";
|
||||
import { avatarForIndex } from "@/app/data/avatars";
|
||||
import { cancelMeetupRsvp, fetchMeetupRsvpStatus, rsvpMeetup } from "@/app/lib/social";
|
||||
import MeetupSocialPanel from "@/app/components/meetups/MeetupSocialPanel";
|
||||
|
||||
function AttendeeAvatar({ attendee, className }: { attendee: Attendee; className?: string }) {
|
||||
const image = (
|
||||
<img
|
||||
src={mediaUrl(attendee.photo)}
|
||||
alt={attendee.name}
|
||||
title={attendee.name}
|
||||
className={className || "h-8 w-8 rounded-full border border-white object-cover shadow-sm dark:border-gray-800"}
|
||||
/>
|
||||
);
|
||||
if (attendee.profileId) {
|
||||
return (
|
||||
<Link href={`/members/${attendee.profileId}`} className="transition hover:scale-105">
|
||||
{image}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
interface Attendee {
|
||||
name: string;
|
||||
photo: string;
|
||||
profileId?: string;
|
||||
userId?: string;
|
||||
}
|
||||
|
||||
interface Meetup {
|
||||
@@ -467,6 +490,15 @@ function toAccessLevel(value: unknown): MeetupAccessLevel {
|
||||
return value === "members" || value === "vip" || value === "hosts" || value === "public" ? value : "public";
|
||||
}
|
||||
|
||||
function computeIsUpcoming(item: { date?: string; time?: string; isUpcoming?: boolean }): boolean {
|
||||
const datePart = String(item.date || "").slice(0, 10);
|
||||
if (!datePart) return Boolean(item.isUpcoming ?? true);
|
||||
const timePart = String(item.time || "23:59").slice(0, 5);
|
||||
const eventAt = new Date(`${datePart}T${timePart}:00`);
|
||||
if (Number.isNaN(eventAt.getTime())) return Boolean(item.isUpcoming ?? true);
|
||||
return eventAt.getTime() > Date.now();
|
||||
}
|
||||
|
||||
function mapMeetup(item: Partial<Meetup> & { id: string; status?: string }): Meetup {
|
||||
const mode = toMeetupMode(item.mode || (item.meetingUrl || item.mirotalkRoom ? "online" : "offline"));
|
||||
return {
|
||||
@@ -482,7 +514,7 @@ function mapMeetup(item: Partial<Meetup> & { id: string; status?: string }): Mee
|
||||
gradientFrom: item.gradientFrom || (mode === "online" ? "#0f766e" : "#ff4d4f"),
|
||||
gradientTo: item.gradientTo || (mode === "online" ? "#2563eb" : "#ff7a45"),
|
||||
attendees: Array.isArray(item.attendees) ? item.attendees : [],
|
||||
isUpcoming: Boolean(item.isUpcoming ?? true),
|
||||
isUpcoming: computeIsUpcoming(item),
|
||||
mode,
|
||||
accessLevel: toAccessLevel(item.accessLevel),
|
||||
meetingProvider: item.meetingProvider || (mode === "offline" ? "" : "mirotalk"),
|
||||
@@ -588,7 +620,11 @@ function MeetupCard({ meetup, locale, viewer, onSelect }: { meetup: Meetup; loca
|
||||
<div className="mt-auto flex items-center gap-1 border-t border-gray-100 pt-4 dark:border-gray-700">
|
||||
<div className="flex -space-x-2">
|
||||
{meetup.attendees.map((a, index) => (
|
||||
<img key={`${a.name}-${index}`} src={mediaUrl(a.photo)} alt={a.name} className="h-7 w-7 rounded-full border-2 border-white object-cover shadow-sm dark:border-gray-800 sm:h-8 sm:w-8" title={a.name} />
|
||||
<AttendeeAvatar
|
||||
key={`${a.name}-${index}`}
|
||||
attendee={a}
|
||||
className="h-7 w-7 rounded-full border-2 border-white object-cover shadow-sm dark:border-gray-800 sm:h-8 sm:w-8"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<span className="ml-1 text-xs text-gray-400 dark:text-gray-500">{locale === "zh" ? "已报名成员" : "attendees"}</span>
|
||||
@@ -598,17 +634,66 @@ function MeetupCard({ meetup, locale, viewer, onSelect }: { meetup: Meetup; loca
|
||||
);
|
||||
}
|
||||
|
||||
function MeetupDetailModal({ meetup, locale, viewer, onClose }: { meetup: Meetup; locale: string; viewer: ViewerState; onClose: () => void }) {
|
||||
function MeetupDetailModal({
|
||||
meetup,
|
||||
locale,
|
||||
viewer,
|
||||
onClose,
|
||||
onMeetupUpdated,
|
||||
}: {
|
||||
meetup: Meetup;
|
||||
locale: string;
|
||||
viewer: ViewerState;
|
||||
onClose: () => void;
|
||||
onMeetupUpdated?: (meetup: Meetup) => void;
|
||||
}) {
|
||||
const c = getCopy(locale);
|
||||
const [embedOpen, setEmbedOpen] = useState(false);
|
||||
const canJoin = canAccessMeetup(meetup, viewer);
|
||||
const joinUrl = buildMiroTalkJoinUrl(meetup, viewerDisplayName(viewer));
|
||||
const chatUrl = buildMeetupChatUrl(meetup);
|
||||
const livePath = buildMeetupLivePath(meetup.id);
|
||||
const [rsvped, setRsvped] = useState(false);
|
||||
const [rsvpLoading, setRsvpLoading] = useState(false);
|
||||
const [localMeetup, setLocalMeetup] = useState(meetup);
|
||||
|
||||
useEffect(() => {
|
||||
setLocalMeetup(meetup);
|
||||
}, [meetup]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!viewer.user?.id) {
|
||||
setRsvped(false);
|
||||
return;
|
||||
}
|
||||
fetchMeetupRsvpStatus(meetup.id).then(setRsvped);
|
||||
}, [meetup.id, viewer.user?.id]);
|
||||
const canJoin = canAccessMeetup(localMeetup, viewer);
|
||||
const joinUrl = buildMiroTalkJoinUrl(localMeetup, viewerDisplayName(viewer));
|
||||
const chatUrl = buildMeetupChatUrl(localMeetup);
|
||||
const livePath = buildMeetupLivePath(localMeetup.id);
|
||||
|
||||
const applyMeetupUpdate = (raw: Record<string, unknown>) => {
|
||||
const next = mapMeetup({ ...raw, id: String(raw.id || localMeetup.id) } as Partial<Meetup> & { id: string });
|
||||
setLocalMeetup(next);
|
||||
onMeetupUpdated?.(next);
|
||||
};
|
||||
|
||||
const handleRsvp = async () => {
|
||||
if (!viewer.user?.id) return;
|
||||
setRsvpLoading(true);
|
||||
try {
|
||||
if (rsvped) {
|
||||
const data = await cancelMeetupRsvp(localMeetup.id);
|
||||
setRsvped(false);
|
||||
if (data.meetup) applyMeetupUpdate(data.meetup);
|
||||
} else {
|
||||
const data = await rsvpMeetup(localMeetup.id);
|
||||
setRsvped(true);
|
||||
if (data.meetup) applyMeetupUpdate(data.meetup);
|
||||
}
|
||||
} finally {
|
||||
setRsvpLoading(false);
|
||||
}
|
||||
};
|
||||
const mirotalkServer = getMiroTalkServerLabel();
|
||||
const loungeServer = getLoungeServerLabel();
|
||||
const isVideoEvent = isLiveMeetup(meetup);
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-[9999] overflow-y-auto">
|
||||
<button type="button" className="fixed inset-0 cursor-default bg-black/55 backdrop-blur-sm" onClick={onClose} aria-label={locale === "zh" ? "关闭活动详情" : "Close event details"} />
|
||||
@@ -626,12 +711,12 @@ function MeetupDetailModal({ meetup, locale, viewer, onClose }: { meetup: Meetup
|
||||
</svg>
|
||||
</button>
|
||||
<div className="flex flex-wrap gap-2 pr-12">
|
||||
<span className="rounded-full bg-white/18 px-2.5 py-1 text-xs font-semibold backdrop-blur">{modeLabel(meetup.mode, locale)}</span>
|
||||
<span className="rounded-full bg-white/18 px-2.5 py-1 text-xs font-semibold backdrop-blur">{accessLabel(meetup.accessLevel, locale)}</span>
|
||||
{meetup.meetingProvider === "mirotalk" && <span className="rounded-full bg-white/18 px-2.5 py-1 text-xs font-semibold backdrop-blur">{MIROTALK_PROVIDER_LABEL}</span>}
|
||||
<span className="rounded-full bg-white/18 px-2.5 py-1 text-xs font-semibold backdrop-blur">{modeLabel(localMeetup.mode, locale)}</span>
|
||||
<span className="rounded-full bg-white/18 px-2.5 py-1 text-xs font-semibold backdrop-blur">{accessLabel(localMeetup.accessLevel, locale)}</span>
|
||||
{localMeetup.meetingProvider === "mirotalk" && <span className="rounded-full bg-white/18 px-2.5 py-1 text-xs font-semibold backdrop-blur">{MIROTALK_PROVIDER_LABEL}</span>}
|
||||
</div>
|
||||
<h2 className="mt-5 text-2xl font-bold sm:text-3xl">{meetup.emoji} {meetup.city} · {meetup.venue}</h2>
|
||||
<p className="mt-2 max-w-2xl text-sm leading-6 text-white/88">{meetup.description}</p>
|
||||
<h2 className="mt-5 text-2xl font-bold sm:text-3xl">{localMeetup.emoji} {localMeetup.city} · {localMeetup.venue}</h2>
|
||||
<p className="mt-2 max-w-2xl text-sm leading-6 text-white/88">{localMeetup.description}</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-5 p-5 sm:p-7 lg:grid-cols-[1.1fr_0.9fr]">
|
||||
@@ -639,32 +724,32 @@ function MeetupDetailModal({ meetup, locale, viewer, onClose }: { meetup: Meetup
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<div className="rounded-xl border border-gray-100 bg-gray-50 p-4 dark:border-gray-800 dark:bg-gray-950">
|
||||
<p className="text-xs font-semibold uppercase tracking-wide text-gray-400">{locale === "zh" ? "时间" : "Time"}</p>
|
||||
<p className="mt-1 text-sm font-semibold text-gray-900 dark:text-gray-100">{formatMeetupDate(meetup.date, meetup.time)}</p>
|
||||
<p className="mt-1 text-sm font-semibold text-gray-900 dark:text-gray-100">{formatMeetupDate(localMeetup.date, localMeetup.time)}</p>
|
||||
</div>
|
||||
<div className="rounded-xl border border-gray-100 bg-gray-50 p-4 dark:border-gray-800 dark:bg-gray-950">
|
||||
<p className="text-xs font-semibold uppercase tracking-wide text-gray-400">{c.organizer}</p>
|
||||
<p className="mt-1 text-sm font-semibold text-gray-900 dark:text-gray-100">{meetup.organizer}</p>
|
||||
<p className="mt-1 text-sm font-semibold text-gray-900 dark:text-gray-100">{localMeetup.organizer}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rounded-xl border border-gray-100 bg-gray-50 p-4 dark:border-gray-800 dark:bg-gray-950">
|
||||
<p className="text-xs font-semibold uppercase tracking-wide text-gray-400">{locale === "zh" ? "地点" : "Location"}</p>
|
||||
<p className="mt-1 text-sm font-semibold text-gray-900 dark:text-gray-100">{meetup.venue}</p>
|
||||
<p className="mt-1 text-sm text-gray-500 dark:text-gray-400">{meetup.address}</p>
|
||||
<p className="mt-1 text-sm font-semibold text-gray-900 dark:text-gray-100">{localMeetup.venue}</p>
|
||||
<p className="mt-1 text-sm text-gray-500 dark:text-gray-400">{localMeetup.address}</p>
|
||||
</div>
|
||||
|
||||
{isVideoEvent && (
|
||||
{isLiveMeetup(localMeetup) && (
|
||||
<div className="rounded-xl border border-emerald-100 bg-emerald-50/70 p-4 dark:border-emerald-900/50 dark:bg-emerald-950/30">
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
|
||||
<div>
|
||||
<p className="text-xs font-semibold uppercase tracking-wide text-emerald-700 dark:text-emerald-300">{c.provider}</p>
|
||||
<p className="mt-1 text-sm font-semibold text-gray-900 dark:text-gray-100">{MIROTALK_PROVIDER_LABEL}</p>
|
||||
<p className="mt-1 break-all text-xs text-gray-500 dark:text-gray-400">{c.room}: {meetup.mirotalkRoom || meetup.id}</p>
|
||||
<p className="mt-1 break-all text-xs text-gray-500 dark:text-gray-400">{c.room}: {localMeetup.mirotalkRoom || localMeetup.id}</p>
|
||||
<p className="mt-1 break-all text-xs text-gray-500 dark:text-gray-400">{c.relayServer}: {mirotalkServer}</p>
|
||||
<p className="mt-2 text-xs font-semibold uppercase tracking-wide text-emerald-700 dark:text-emerald-300">{c.chatService}</p>
|
||||
<p className="mt-1 text-sm font-semibold text-gray-900 dark:text-gray-100">{WEB_CHAT_PROVIDER_LABEL}</p>
|
||||
<p className="mt-1 break-all text-xs text-gray-500 dark:text-gray-400">{c.chatServer}: {loungeServer}</p>
|
||||
<p className="mt-1 break-all text-xs text-gray-500 dark:text-gray-400">{c.chatChannel}: {meetup.loungeChannel || `#${meetup.mirotalkRoom || meetup.id}`}</p>
|
||||
<p className="mt-1 break-all text-xs text-gray-500 dark:text-gray-400">{c.chatChannel}: {localMeetup.loungeChannel || `#${localMeetup.mirotalkRoom || localMeetup.id}`}</p>
|
||||
</div>
|
||||
{canJoin ? (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
@@ -699,18 +784,18 @@ function MeetupDetailModal({ meetup, locale, viewer, onClose }: { meetup: Meetup
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<p className="rounded-lg border border-red-200 bg-white px-3 py-2 text-sm font-semibold text-red-600 dark:border-red-900/60 dark:bg-gray-900 dark:text-red-300">{lockedReason(meetup, locale)}</p>
|
||||
<p className="rounded-lg border border-red-200 bg-white px-3 py-2 text-sm font-semibold text-red-600 dark:border-red-900/60 dark:bg-gray-900 dark:text-red-300">{lockedReason(localMeetup, locale)}</p>
|
||||
)}
|
||||
</div>
|
||||
{canJoin && meetup.accessLevel === "public" && (
|
||||
{canJoin && localMeetup.accessLevel === "public" && (
|
||||
<p className="mt-3 text-xs text-emerald-700 dark:text-emerald-300">{c.authPublicHint}</p>
|
||||
)}
|
||||
{canJoin && (
|
||||
<p className="mt-2 text-xs text-emerald-700 dark:text-emerald-300">{c.chatHint}</p>
|
||||
)}
|
||||
{meetup.replayUrl ? (
|
||||
{localMeetup.replayUrl ? (
|
||||
<a
|
||||
href={meetup.replayUrl}
|
||||
href={localMeetup.replayUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="mt-3 inline-flex text-sm font-semibold text-emerald-700 underline dark:text-emerald-300"
|
||||
@@ -720,7 +805,7 @@ function MeetupDetailModal({ meetup, locale, viewer, onClose }: { meetup: Meetup
|
||||
) : null}
|
||||
{embedOpen && canJoin && (
|
||||
<iframe
|
||||
title={`MiroTalk ${meetup.city}`}
|
||||
title={`MiroTalk ${localMeetup.city}`}
|
||||
src={joinUrl}
|
||||
className="mt-4 h-[360px] w-full rounded-xl border border-emerald-200 bg-black dark:border-emerald-900 sm:h-[460px]"
|
||||
allow="camera; microphone; display-capture; fullscreen; clipboard-read; clipboard-write"
|
||||
@@ -735,8 +820,8 @@ function MeetupDetailModal({ meetup, locale, viewer, onClose }: { meetup: Meetup
|
||||
<div className="rounded-xl border border-gray-100 p-4 dark:border-gray-800">
|
||||
<h3 className="text-sm font-bold text-gray-900 dark:text-gray-100">{c.featureTitle}</h3>
|
||||
<div className="mt-3 flex flex-wrap gap-2">
|
||||
{(featureLabels(meetup.features, locale).length ? featureLabels(meetup.features, locale) : [modeLabel(meetup.mode, locale)]).map((feature) => (
|
||||
<Badge key={feature} tone={meetup.mode === "offline" ? "gray" : "green"}>{feature}</Badge>
|
||||
{(featureLabels(localMeetup.features, locale).length ? featureLabels(localMeetup.features, locale) : [modeLabel(localMeetup.mode, locale)]).map((feature) => (
|
||||
<Badge key={feature} tone={localMeetup.mode === "offline" ? "gray" : "green"}>{feature}</Badge>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
@@ -754,13 +839,50 @@ function MeetupDetailModal({ meetup, locale, viewer, onClose }: { meetup: Meetup
|
||||
<div className="rounded-xl border border-gray-100 p-4 dark:border-gray-800">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="text-sm text-gray-500 dark:text-gray-400">{locale === "zh" ? "当前权限" : "Your access"}</span>
|
||||
<Badge tone={canJoin ? "green" : "red"}>{canJoin ? accessLabel(meetup.accessLevel, locale) : lockedReason(meetup, locale)}</Badge>
|
||||
<Badge tone={canJoin ? "green" : "red"}>{canJoin ? accessLabel(localMeetup.accessLevel, locale) : lockedReason(localMeetup, locale)}</Badge>
|
||||
</div>
|
||||
<div className="mt-3 flex items-center justify-between gap-3">
|
||||
<span className="text-sm text-gray-500 dark:text-gray-400">{locale === "zh" ? "报名人数" : "RSVPs"}</span>
|
||||
<span className="text-sm font-semibold text-gray-900 dark:text-gray-100">{meetup.rsvpCount}{meetup.maxAttendees ? ` / ${meetup.maxAttendees}` : ""}</span>
|
||||
<span className="text-sm font-semibold text-gray-900 dark:text-gray-100">{localMeetup.rsvpCount}{localMeetup.maxAttendees ? ` / ${localMeetup.maxAttendees}` : ""}</span>
|
||||
</div>
|
||||
{localMeetup.isUpcoming ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleRsvp}
|
||||
disabled={rsvpLoading || !viewer.user?.id}
|
||||
className={`mt-4 w-full rounded-xl px-4 py-3 text-sm font-semibold transition ${
|
||||
rsvped
|
||||
? "border border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-900 dark:bg-emerald-950/30 dark:text-emerald-300"
|
||||
: "bg-[#ff4d4f] text-white hover:bg-[#ff7a45]"
|
||||
} disabled:cursor-not-allowed disabled:opacity-60`}
|
||||
>
|
||||
{!viewer.user?.id
|
||||
? locale === "zh"
|
||||
? "登录后报名"
|
||||
: "Log in to RSVP"
|
||||
: rsvpLoading
|
||||
? locale === "zh"
|
||||
? "处理中..."
|
||||
: "Processing..."
|
||||
: rsvped
|
||||
? locale === "zh"
|
||||
? "已报名 · 取消"
|
||||
: "Going · Cancel"
|
||||
: locale === "zh"
|
||||
? "我要参加"
|
||||
: "RSVP"}
|
||||
</button>
|
||||
) : null}
|
||||
{localMeetup.attendees.length > 0 ? (
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
{localMeetup.attendees.slice(0, 8).map((attendee, index) => (
|
||||
<AttendeeAvatar key={`${attendee.name}-${index}`} attendee={attendee} />
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<MeetupSocialPanel meetupId={localMeetup.id} city={localMeetup.city} locale={locale} compact />
|
||||
</aside>
|
||||
</div>
|
||||
</section>
|
||||
@@ -959,7 +1081,17 @@ export default function MeetupsPage() {
|
||||
</main>
|
||||
|
||||
{selectedMeetup && (
|
||||
<MeetupDetailModal key={selectedMeetup.id} meetup={selectedMeetup} locale={locale} viewer={viewer} onClose={() => setSelectedMeetup(null)} />
|
||||
<MeetupDetailModal
|
||||
key={selectedMeetup.id}
|
||||
meetup={selectedMeetup}
|
||||
locale={locale}
|
||||
viewer={viewer}
|
||||
onClose={() => setSelectedMeetup(null)}
|
||||
onMeetupUpdated={(updated) => {
|
||||
setMeetups((current) => current.map((item) => (item.id === updated.id ? updated : item)));
|
||||
setSelectedMeetup(updated);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
141
app/[locale]/members/[id]/page.tsx
Normal file
141
app/[locale]/members/[id]/page.tsx
Normal file
@@ -0,0 +1,141 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link, useLocale } from "@/i18n/navigation";
|
||||
import { useParams } from "next/navigation";
|
||||
import Footer from "@/app/components/Footer";
|
||||
import SocialGreetButton from "@/app/components/SocialGreetButton";
|
||||
import { mediaUrl } from "@/app/lib/media";
|
||||
import { fetchPublicProfile, type PublicProfile } from "@/app/lib/social";
|
||||
|
||||
const INTENT_LABELS: Record<string, string> = {
|
||||
friends: "🤝 交友",
|
||||
dating: "🌹 约会",
|
||||
partner: "👥 搭档",
|
||||
roommate: "🏠 室友",
|
||||
cofounder: "🚀 合伙人",
|
||||
explore: "🍜 探店",
|
||||
};
|
||||
|
||||
export default function MemberProfilePage() {
|
||||
const params = useParams();
|
||||
const profileId = String(params?.id || "");
|
||||
const locale = useLocale();
|
||||
const [profile, setProfile] = useState<PublicProfile | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (!profileId) return;
|
||||
fetchPublicProfile(profileId)
|
||||
.then(setProfile)
|
||||
.finally(() => setLoading(false));
|
||||
}, [profileId]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="min-h-screen bg-[#fafafa] dark:bg-gray-950">
|
||||
<div className="mx-auto max-w-2xl animate-pulse px-4 py-10">
|
||||
<div className="h-64 rounded-2xl bg-gray-200 dark:bg-gray-800" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!profile) {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-[#fafafa] px-4 dark:bg-gray-950">
|
||||
<div className="text-center">
|
||||
<p className="text-gray-500">{locale === "zh" ? "成员资料不存在" : "Profile not found"}</p>
|
||||
<Link href="/dating" className="mt-4 inline-block text-[#ff4d4f]">
|
||||
{locale === "zh" ? "去智能匹配" : "Go to matching"}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const lookingFor = Array.isArray(profile.lookingFor) ? profile.lookingFor : [];
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[#fafafa] dark:bg-gray-950">
|
||||
<main className="mx-auto max-w-2xl px-4 py-8 sm:px-6">
|
||||
<div className="overflow-hidden rounded-2xl border border-gray-100 bg-white shadow-sm dark:border-gray-800 dark:bg-gray-900">
|
||||
<div className="bg-gradient-to-br from-[#ff4d4f] to-[#ff7a45] px-6 py-8 text-white">
|
||||
<div className="flex items-center gap-4">
|
||||
<img
|
||||
src={mediaUrl(profile.photo)}
|
||||
alt={profile.name || "member"}
|
||||
className="h-20 w-20 rounded-full border-4 border-white/30 object-cover"
|
||||
/>
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">
|
||||
{profile.name}
|
||||
{profile.age ? `,${profile.age}` : ""}
|
||||
</h1>
|
||||
<p className="mt-1 text-sm text-white/85">📍 {profile.location || (locale === "zh" ? "远程" : "Remote")}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-5 p-6">
|
||||
{profile.bio ? (
|
||||
<section>
|
||||
<h2 className="text-sm font-semibold text-gray-900 dark:text-gray-100">
|
||||
{locale === "zh" ? "自我介绍" : "About"}
|
||||
</h2>
|
||||
<p className="mt-2 text-sm leading-7 text-gray-600 dark:text-gray-300">{profile.bio}</p>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
{lookingFor.length > 0 ? (
|
||||
<section>
|
||||
<h2 className="text-sm font-semibold text-gray-900 dark:text-gray-100">
|
||||
{locale === "zh" ? "正在寻找" : "Looking for"}
|
||||
</h2>
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
{lookingFor.map((intent) => (
|
||||
<span
|
||||
key={intent}
|
||||
className="rounded-full bg-gray-100 px-3 py-1 text-xs font-medium text-gray-700 dark:bg-gray-800 dark:text-gray-300"
|
||||
>
|
||||
{INTENT_LABELS[intent] || intent}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
{profile.tags?.length ? (
|
||||
<section>
|
||||
<h2 className="text-sm font-semibold text-gray-900 dark:text-gray-100">
|
||||
{locale === "zh" ? "标签" : "Tags"}
|
||||
</h2>
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
{profile.tags.map((tag) => (
|
||||
<span
|
||||
key={tag}
|
||||
className="rounded-full bg-red-50 px-3 py-1 text-xs text-[#ff4d4f] dark:bg-red-950/30"
|
||||
>
|
||||
{tag}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
<div className="flex flex-wrap gap-3 border-t border-gray-100 pt-5 dark:border-gray-800">
|
||||
<Link
|
||||
href={`/dating?intent=${lookingFor[0] || "friends"}${profile.citySlug ? `&city=${profile.citySlug}` : ""}`}
|
||||
className="rounded-full border border-gray-200 px-4 py-2 text-sm font-semibold text-gray-700 dark:border-gray-700 dark:text-gray-200"
|
||||
>
|
||||
{locale === "zh" ? "在匹配里找 TA" : "Find in matching"}
|
||||
</Link>
|
||||
<SocialGreetButton profileId={profile.id} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -10,7 +10,9 @@ import CityModal from "../components/CityModal";
|
||||
import Footer from "@/app/components/Footer";
|
||||
import { cities, type City } from "../data/cities";
|
||||
import { HOME_CONFIG } from "@/config";
|
||||
import { useDevDebug } from "@/app/context/DevDebugContext";
|
||||
import { apiFetch } from "@/app/lib/api-client";
|
||||
import { cityWeatherKey, type CityWeatherMap } from "@/app/lib/city-weather";
|
||||
import { mediaUrl } from "@/app/lib/media";
|
||||
|
||||
const {
|
||||
@@ -177,6 +179,7 @@ export default function Home() {
|
||||
const [sortBy, setSortBy] = useState("score");
|
||||
const [cityModal, setCityModal] = useState<City | null>(null);
|
||||
const [liveCities, setLiveCities] = useState<City[]>(cities);
|
||||
const [cityWeather, setCityWeather] = useState<CityWeatherMap>({});
|
||||
const [homeContent, setHomeContent] = useState<ContentItem[]>(FALLBACK_HOME_CONTENT);
|
||||
const [homeStats, setHomeStats] = useState<HomeStats>(fallbackStats);
|
||||
const [memberPhotos, setMemberPhotos] = useState(fallbackMemberPhotos);
|
||||
@@ -184,6 +187,7 @@ export default function Home() {
|
||||
const [communityStats, setCommunityStats] = useState(fallbackCommunityStats);
|
||||
const locale = useLocale();
|
||||
const { t } = useTranslation("home");
|
||||
const { isFeatureVisible } = useDevDebug();
|
||||
|
||||
useEffect(() => {
|
||||
apiFetch<{ ok: boolean; items: City[] }>("/api/cities")
|
||||
@@ -193,6 +197,13 @@ export default function Home() {
|
||||
}
|
||||
})
|
||||
.catch(() => setLiveCities(cities));
|
||||
apiFetch<{ ok: boolean; items: CityWeatherMap }>("/api/weather/cities")
|
||||
.then((data) => {
|
||||
if (data.items && typeof data.items === "object") {
|
||||
setCityWeather(data.items);
|
||||
}
|
||||
})
|
||||
.catch(() => setCityWeather({}));
|
||||
apiFetch<{ ok: boolean; items: ContentItem[] }>("/api/content/home")
|
||||
.then((data) => {
|
||||
const items = (data.items || [])
|
||||
@@ -260,19 +271,22 @@ export default function Home() {
|
||||
return safetyOrder(b.safety) - safetyOrder(a.safety);
|
||||
case "nomads":
|
||||
return b.nomadsNow - a.nomadsNow;
|
||||
case "temperature":
|
||||
return b.temperature - a.temperature;
|
||||
case "temperature": {
|
||||
const tempA = cityWeather[cityWeatherKey(a)]?.temperature ?? a.temperature;
|
||||
const tempB = cityWeather[cityWeatherKey(b)]?.temperature ?? b.temperature;
|
||||
return tempB - tempA;
|
||||
}
|
||||
default:
|
||||
return b.overallScore - a.overallScore;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}, [activeFilter, sortBy, liveCities]);
|
||||
}, [activeFilter, sortBy, liveCities, cityWeather]);
|
||||
|
||||
const homepageFeatureContent = useMemo(
|
||||
() => pickHomepageFeatureContent(homeContent),
|
||||
[homeContent]
|
||||
);
|
||||
const homepageFeatureContent = useMemo(() => {
|
||||
if (!isFeatureVisible("home.rightFeatureCards")) return [];
|
||||
return pickHomepageFeatureContent(homeContent);
|
||||
}, [homeContent, isFeatureVisible]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[#fafafa] dark:bg-gray-950">
|
||||
@@ -442,6 +456,7 @@ export default function Home() {
|
||||
key={city.id}
|
||||
city={city}
|
||||
rank={i + 1}
|
||||
liveWeather={cityWeather[cityWeatherKey(city)] ?? null}
|
||||
onClick={() => setCityModal(city)}
|
||||
/>
|
||||
))}
|
||||
@@ -467,7 +482,7 @@ export default function Home() {
|
||||
isOpen={!!cityModal}
|
||||
onClose={() => setCityModal(null)}
|
||||
/>
|
||||
<Footer />
|
||||
<Footer minimal />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user