nomadro/src/modules/social/components/PlaceDetailClient.tsx
Eric 35e5f863fe Retitle social IA and float feedback as a corner mate.
Move 想见的人 to 一起做事/找搭子, rename gigs to 招聘, hide skill swap and the motion toggle, keep coffeechat online-backed, and add a non-dismissive feedback orb.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-09 20:33:03 +08:00

509 lines
17 KiB
TypeScript

"use client";
import { useEffect, useMemo, useState } from "react";
import Link from "next/link";
import {
ArrowLeft,
ArrowUpRight,
Coffee,
MapPin,
Radio,
Users,
Wifi,
Sparkles,
Navigation,
} from "lucide-react";
import dynamic from "next/dynamic";
import SiteShell from "./SiteShell";
import SocialAvatar from "./SocialAvatar";
import { getCityById, SOCIAL_CITIES } from "@social/lib/cities";
import { socialApi } from "@social/lib/api";
import type { SocialMapCity } from "@social/lib/geoTypes";
import { resolveSocialCatalog } from "@social/lib/resolveCatalog";
import { useDiscoveryRoster } from "@social/lib/discoveryRoster";
import { socialPath } from "@social/lib/socialPath";
import { socialTx } from "@social/lib/socialTx";
import { txCity } from "@social/lib/localizeEntity";
import { useSocialI18n } from "@social/lib/useSocialI18n";
import { useSocialConfig } from "./SocialExperience";
const PlaceMapPreview = dynamic(() => import("./PlaceMapPreview"), {
ssr: false,
loading: () => <div className="spd-map-frame spd-map-frame--loading" />,
});
type Props = { cityId: string };
type LiveCity = SocialMapCity & {
recentArrivals?: Array<{
guestId: string;
status: string;
arrival_date: string;
}>;
blurb?: string;
highlights?: string[];
cover?: string;
};
const FALLBACK_COVER =
"https://images.unsplash.com/photo-1480714378408-67cf0d13bc1b?auto=format&fit=crop&w=1400&q=75";
export default function PlaceDetailClient({ cityId }: Props) {
const seed = getCityById(cityId);
const { portalLocale } = useSocialI18n();
const config = useSocialConfig();
const catalog = useMemo(
() => resolveSocialCatalog(config.copy.socialCatalogs),
[config.copy.socialCatalogs, portalLocale],
);
const roster = useDiscoveryRoster();
const [city, setCity] = useState<LiveCity | null>(
seed
? {
id: seed.id,
name: seed.name,
country: seed.country,
emoji: seed.emoji,
vibe: seed.vibe,
blurb: seed.blurb,
highlights: seed.highlights,
cover: seed.cover,
lat: seed.lat,
lng: seed.lng,
memberCount: seed.members,
meetupCount: seed.meetupCount || 0,
costHint: seed.costHint,
wifiMbps: seed.wifiMbps,
tags: seed.tags,
hot: seed.hot,
}
: null,
);
useEffect(() => {
let alive = true;
void socialApi
.cityDetail(cityId)
.then((res) => {
if (!alive || !res.item) return;
setCity((prev) => ({
...prev,
...res.item,
blurb: prev?.blurb || seed?.blurb,
highlights: prev?.highlights || seed?.highlights,
cover: prev?.cover || seed?.cover,
wifiMbps: res.item.wifiMbps ?? prev?.wifiMbps ?? seed?.wifiMbps,
tags: res.item.tags?.length ? res.item.tags : prev?.tags || seed?.tags,
}));
})
.catch(() => {});
return () => {
alive = false;
};
}, [cityId, seed]);
const cityName = city?.name || seed?.name || "";
const cafes = useMemo(
() =>
catalog.cafes.filter(
(c) =>
c.city === cityName ||
c.city.includes(cityName) ||
cityName.includes(c.city),
),
[catalog.cafes, cityName],
);
const meetups = useMemo(
() =>
catalog.meetups.filter(
(m) =>
m.city === cityName ||
m.city.includes(cityName) ||
(m.city === "Online" && Boolean(city?.hot)),
),
[catalog.meetups, cityName, city?.hot],
);
const people = useMemo(() => {
const needle = cityName.toLowerCase();
return roster
.filter((m) => {
const c = (m.city || "").toLowerCase();
return c.includes(needle) || needle.includes(c.split(/[→\-·]/)[0].trim());
})
.slice(0, 8);
}, [roster, cityName]);
const nearby = useMemo(() => {
if (!city) return [];
return SOCIAL_CITIES.filter((c) => c.id !== city.id)
.map((c) => ({
c,
d:
(c.lat - city.lat) ** 2 +
(c.lng - city.lng) ** 2 +
(c.country === city.country ? 0 : 0.4),
}))
.sort((a, b) => a.d - b.d)
.slice(0, 4)
.map((x) => x.c);
}, [city]);
if (!city) {
return (
<SiteShell title={socialTx("城市")}>
<div className="spd-empty">
<h1>{socialTx("找不到这座城市")}</h1>
<p>{socialTx("换一座试试")}</p>
<Link className="social-btn" href={socialPath("/places")}>
{socialTx("返回城市目录")}
</Link>
</div>
</SiteShell>
);
}
const cover = city.cover || seed?.cover || FALLBACK_COVER;
const display = seed
? txCity({
...seed,
name: city.name || seed.name,
country: city.country || seed.country,
vibe: city.vibe || seed.vibe,
blurb: city.blurb || seed.blurb,
highlights: city.highlights || seed.highlights,
costHint: city.costHint || seed.costHint,
tags: city.tags?.length ? city.tags : seed.tags,
hot: city.hot ?? seed.hot,
members: city.memberCount || seed.members,
meetupCount: city.meetupCount || seed.meetupCount,
wifiMbps: city.wifiMbps || seed.wifiMbps,
})
: {
name: socialTx(city.name),
country: socialTx(city.country),
vibe: socialTx(city.vibe || ""),
blurb: city.blurb ? socialTx(city.blurb) : undefined,
costHint: city.costHint ? socialTx(city.costHint) : "",
tags: (city.tags || []).map((t) => socialTx(t)),
highlights: city.highlights?.map((h) => socialTx(h)),
};
return (
<SiteShell title={display.name} immersive>
<article className="spd">
<section className="spd-stage">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img className="spd-stage-photo" src={cover} alt="" />
<div className="spd-stage-veil" aria-hidden />
<div className="spd-stage-grain" aria-hidden />
<div className="spd-stage-inner">
<Link className="spd-back" href={socialPath("/places")}>
<ArrowLeft size={16} aria-hidden />
{socialTx("城市目录")}
</Link>
<div className="spd-stage-copy">
<p className="spd-kicker">
<span>{city.emoji}</span>
{display.country}
{city.hot ? <em>HOT</em> : null}
</p>
<h1 className="spd-brand">{display.name}</h1>
<p className="spd-vibe">{display.vibe}</p>
{display.blurb ? <p className="spd-blurb">{display.blurb}</p> : null}
{display.tags?.length ? (
<div className="spd-tags">
{display.tags.map((t) => (
<span key={t}>{t}</span>
))}
</div>
) : null}
<div className="spd-cta">
<Link
className="spd-btn spd-btn-primary"
href={socialPath(
`/people?city=${encodeURIComponent(city.name)}`,
)}
>
{socialTx("找搭子")}
<ArrowUpRight size={16} aria-hidden />
</Link>
<Link
className="spd-btn"
href={socialPath(`/map?city=${encodeURIComponent(city.id)}`)}
>
<Navigation size={15} aria-hidden />
{socialTx("打开地图")}
</Link>
<Link
className="spd-btn"
href={socialPath(
`/places?tab=cafes&city=${encodeURIComponent(city.name)}`,
)}
>
<Coffee size={15} aria-hidden />
{socialTx("咖啡馆见面")}
</Link>
</div>
</div>
</div>
</section>
<section className="spd-stats" aria-label={socialTx("城市概览")}>
<div className="spd-stat">
<Users size={16} aria-hidden />
<span className="spd-stat-text">
<b>{city.memberCount}</b>
<small>{socialTx("位游民")}</small>
</span>
</div>
<div className="spd-stat">
<Radio size={16} aria-hidden />
<span className="spd-stat-text">
<b>{city.meetupCount || meetups.length || 0}</b>
<small>{socialTx("场局")}</small>
</span>
</div>
<div className="spd-stat">
<Wifi size={16} aria-hidden />
<span className="spd-stat-text">
<b>{city.wifiMbps || seed?.wifiMbps || "—"}</b>
<small>Mbps</small>
</span>
</div>
<div className="spd-stat">
<MapPin size={16} aria-hidden />
<span className="spd-stat-text">
<b className="spd-stat-cost">{display.costHint || "—"}</b>
<small>{socialTx("生活成本")}</small>
</span>
</div>
{(city.currentlyHere || 0) > 0 ? (
<div className="spd-stat">
<Sparkles size={16} aria-hidden />
<span className="spd-stat-text">
<b>{city.currentlyHere}</b>
<small>{socialTx("此刻在这")}</small>
</span>
</div>
) : null}
</section>
<div className="spd-body">
{display.highlights?.length ? (
<section className="spd-panel spd-why">
<header className="spd-sec-head">
<p>{socialTx("旅居感")}</p>
<h2>{socialTx("为什么待这儿")}</h2>
</header>
<ol className="spd-highlights">
{display.highlights.map((h, i) => (
<li key={h}>
<em>{String(i + 1).padStart(2, "0")}</em>
<span>{h}</span>
</li>
))}
</ol>
</section>
) : null}
<div className="spd-split">
<section className="spd-panel">
<header className="spd-panel-head">
<h2>
<Coffee size={18} aria-hidden /> {socialTx("咖啡馆见面")}
</h2>
<Link
href={socialPath(
`/places?tab=cafes&city=${encodeURIComponent(city.name)}`,
)}
>
{socialTx("全部")} <ArrowUpRight size={14} aria-hidden />
</Link>
</header>
{cafes.length ? (
<ul className="spd-cards">
{cafes.slice(0, 4).map((cafe) => (
<li key={cafe.id}>
<Link
className="spd-card"
href={socialPath(
`/places?tab=cafes&city=${encodeURIComponent(city.name)}#${cafe.id}`,
)}
>
<span className="spd-card-ico" aria-hidden>
☕
</span>
<span className="spd-card-copy">
<strong>{cafe.name}</strong>
<small>
★ {cafe.rating} · {cafe.wifiMbps}M · {cafe.vibe}
</small>
</span>
<ArrowUpRight size={16} aria-hidden />
</Link>
</li>
))}
</ul>
) : (
<p className="spd-muted">
{socialTx(
"这座城市的咖啡馆点还在补齐,先去地图或同城人里逛逛。",
)}
</p>
)}
</section>
<section className="spd-panel">
<header className="spd-panel-head">
<h2>
<Radio size={18} aria-hidden /> {socialTx("同城 / 线上局")}
</h2>
<Link href={socialPath("/meetup")}>
{socialTx("更多")} <ArrowUpRight size={14} aria-hidden />
</Link>
</header>
{meetups.length ? (
<ul className="spd-cards">
{meetups.slice(0, 4).map((m) => (
<li key={m.id}>
<Link className="spd-card" href={socialPath(`/meetup/${m.id}`)}>
<span className="spd-card-ico is-radio" aria-hidden>
📡
</span>
<span className="spd-card-copy">
<strong>{m.title}</strong>
<small>
{m.city} · {m.date} {m.time}
{m.mode ? ` · ${m.mode}` : ""}
</small>
</span>
<ArrowUpRight size={16} aria-hidden />
</Link>
</li>
))}
</ul>
) : (
<p className="spd-muted">
{socialTx("暂时没有排期,去聊天厅问问有没有局。")}
</p>
)}
</section>
</div>
<section className="spd-panel">
<header className="spd-panel-head">
<h2>
<Users size={18} aria-hidden /> {socialTx("同城的人")}
</h2>
<Link
href={socialPath(`/people?city=${encodeURIComponent(city.name)}`)}
>
{socialTx("花名册")} <ArrowUpRight size={14} aria-hidden />
</Link>
</header>
{people.length ? (
<div className="spd-people">
{people.map((p) => (
<Link
key={p.id}
href={socialPath(`/people/${p.id}`)}
className="spd-person"
>
<SocialAvatar
src={p.avatar}
size={48}
lazy
faceOk={p.faceOk}
/>
<span>
<strong>{p.name}</strong>
<em>{p.title || p.city}</em>
</span>
</Link>
))}
</div>
) : (
<p className="spd-muted">
{socialTx("还没有公开的同城介绍,去做第一个。")}
</p>
)}
</section>
<section className="spd-map">
<header className="spd-panel-head">
<h2>
<MapPin size={18} aria-hidden /> {socialTx("在地图上")}
</h2>
<Link href={socialPath(`/map?city=${encodeURIComponent(city.id)}`)}>
{socialTx("打开社区地图")} <ArrowUpRight size={14} aria-hidden />
</Link>
</header>
<PlaceMapPreview
name={city.name}
lat={city.lat}
lng={city.lng}
emoji={city.emoji}
/>
</section>
{city.recentArrivals?.length ? (
<section className="spd-panel">
<h2>{socialTx("近期抵达")}</h2>
<ul className="spd-arrivals">
{city.recentArrivals.map((a, i) => (
<li key={`${a.guestId}-${i}`}>
<strong>{a.guestId}</strong>
<span>
{a.status === "here"
? socialTx("在这儿")
: socialTx("计划中")}
</span>
{a.arrival_date ? <em>{a.arrival_date}</em> : null}
</li>
))}
</ul>
</section>
) : null}
{nearby.length ? (
<section className="spd-nearby">
<header className="spd-sec-head">
<p>{socialTx("继续逛")}</p>
<h2>{socialTx("附近 / 下一站")}</h2>
</header>
<div className="spd-nearby-grid">
{nearby.map((n) => (
<Link
key={n.id}
href={socialPath(`/places/${n.id}`)}
className="spd-nearby-card"
>
{n.cover ? (
// eslint-disable-next-line @next/next/no-img-element
<img src={n.cover} alt="" loading="lazy" />
) : (
<span className="spd-nearby-emoji" aria-hidden>
{n.emoji}
</span>
)}
<div>
<strong>
{n.emoji} {n.name}
</strong>
<em>{n.vibe}</em>
</div>
</Link>
))}
</div>
</section>
) : null}
</div>
</article>
</SiteShell>
);
}