Shield external portal jumps (keep EXTERNAL_* for later), serve /nav from static build, and proxy /book + /community to vertical Next apps with Caddy notes. Co-authored-by: Cursor <cursoragent@cursor.com>
109 lines
3.5 KiB
TypeScript
109 lines
3.5 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import Link from "next/link";
|
|
import { api } from "@/lib/api";
|
|
import { useAuth } from "@/lib/auth";
|
|
import { useI18n } from "@/lib/i18n";
|
|
import type { ConversationItem } from "@/lib/types";
|
|
import RingNext from "@/components/RingNext";
|
|
import { useRingSteps } from "@/lib/rings";
|
|
|
|
function Avatar({ photo, name }: { photo?: string; name?: string }) {
|
|
if (photo?.startsWith("http")) {
|
|
return (
|
|
// eslint-disable-next-line @next/next/no-img-element
|
|
<img src={photo} alt="" className="chat-avatar-img" />
|
|
);
|
|
}
|
|
return <span className="chat-avatar">{photo || name?.[0] || "💬"}</span>;
|
|
}
|
|
|
|
export default function ChatClient() {
|
|
const { user, token } = useAuth();
|
|
const { t } = useI18n();
|
|
const rings = useRingSteps();
|
|
const [items, setItems] = useState<ConversationItem[]>([]);
|
|
const [loading, setLoading] = useState(Boolean(token));
|
|
|
|
useEffect(() => {
|
|
if (!token) {
|
|
setLoading(false);
|
|
return;
|
|
}
|
|
setLoading(true);
|
|
api
|
|
.getConversations(token)
|
|
.then(setItems)
|
|
.catch(() => setItems([]))
|
|
.finally(() => setLoading(false));
|
|
}, [token]);
|
|
|
|
if (!user) {
|
|
return (
|
|
<div className="chat-page">
|
|
<div className="container">
|
|
<div className="dating-gate reveal">
|
|
<h2>{t.chat.loginTitle}</h2>
|
|
<p>{t.chat.loginDesc}</p>
|
|
<div className="dating-empty-actions">
|
|
<Link href="/login?next=/chat" className="btn btn-primary">{t.nav.login}</Link>
|
|
<Link href="/meetups" className="btn btn-ghost">{t.dating.meetAtEvents}</Link>
|
|
<Link href="/dating" className="btn btn-ghost">{t.chat.goDating}</Link>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="chat-page">
|
|
<div className="container">
|
|
<nav className="detail-nav">
|
|
<Link href="/dating">{t.nav.dating}</Link>
|
|
</nav>
|
|
<div className="section-header reveal">
|
|
<span className="section-tag">{t.chat.tag}</span>
|
|
<h1>{t.chat.title}</h1>
|
|
</div>
|
|
<div className="chat-list">
|
|
{loading && <p className="dest-empty">{t.chat.loadingList}</p>}
|
|
{!loading &&
|
|
items.map((c) => (
|
|
<Link
|
|
key={c.id}
|
|
href={`/chat/${c.id}`}
|
|
className={`chat-list-item reveal${c.unreadCount > 0 ? " unread" : ""}`}
|
|
>
|
|
<Avatar photo={c.peer?.photo} name={c.peer?.name} />
|
|
<div>
|
|
<strong>{c.peer?.name || t.chat.peerFallback}</strong>
|
|
<p>{c.lastMessagePreview || t.chat.noMessages}</p>
|
|
</div>
|
|
{c.unreadCount > 0 && <em className="chat-unread">{c.unreadCount}</em>}
|
|
</Link>
|
|
))}
|
|
{!loading && items.length === 0 && (
|
|
<div className="notif-empty reveal">
|
|
<p className="dest-empty">{t.chat.empty}</p>
|
|
<div className="dating-empty-actions">
|
|
<Link href="/dating" className="btn btn-primary btn-sm">
|
|
{t.chat.goDating}
|
|
</Link>
|
|
<Link href="/meetups" className="btn btn-sm">
|
|
{t.dating.meetAtEvents}
|
|
</Link>
|
|
<Link href="/community" className="btn btn-sm">
|
|
{t.nav.community}
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
<RingNext steps={rings.afterDating} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|