"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: () =>
, }); 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( 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 (

{socialTx("找不到这座城市")}

{socialTx("换一座试试")}

{socialTx("返回城市目录")}
); } 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 (
{/* eslint-disable-next-line @next/next/no-img-element */}
{socialTx("城市目录")}

{city.emoji} {display.country} {city.hot ? HOT : null}

{display.name}

{display.vibe}

{display.blurb ?

{display.blurb}

: null} {display.tags?.length ? (
{display.tags.map((t) => ( {t} ))}
) : null}
{socialTx("找搭子")} {socialTx("打开地图")} {socialTx("咖啡馆见面")}
{city.memberCount} {socialTx("位游民")}
{city.meetupCount || meetups.length || 0} {socialTx("场局")}
{city.wifiMbps || seed?.wifiMbps || "—"} Mbps
{display.costHint || "—"} {socialTx("生活成本")}
{(city.currentlyHere || 0) > 0 ? (
{city.currentlyHere} {socialTx("此刻在这")}
) : null}
{display.highlights?.length ? (

{socialTx("旅居感")}

{socialTx("为什么待这儿")}

    {display.highlights.map((h, i) => (
  1. {String(i + 1).padStart(2, "0")} {h}
  2. ))}
) : null}

{socialTx("咖啡馆见面")}

{socialTx("全部")}
{cafes.length ? (
    {cafes.slice(0, 4).map((cafe) => (
  • ☕ {cafe.name} ★ {cafe.rating} · {cafe.wifiMbps}M · {cafe.vibe}
  • ))}
) : (

{socialTx( "这座城市的咖啡馆点还在补齐,先去地图或同城人里逛逛。", )}

)}

{socialTx("同城 / 线上局")}

{socialTx("更多")}
{meetups.length ? (
    {meetups.slice(0, 4).map((m) => (
  • 📡 {m.title} {m.city} · {m.date} {m.time} {m.mode ? ` · ${m.mode}` : ""}
  • ))}
) : (

{socialTx("暂时没有排期,去聊天厅问问有没有局。")}

)}

{socialTx("同城的人")}

{socialTx("花名册")}
{people.length ? (
{people.map((p) => ( {p.name} {p.title || p.city} ))}
) : (

{socialTx("还没有公开的同城介绍,去做第一个。")}

)}

{socialTx("在地图上")}

{socialTx("打开社区地图")}
{city.recentArrivals?.length ? (

{socialTx("近期抵达")}

    {city.recentArrivals.map((a, i) => (
  • {a.guestId} {a.status === "here" ? socialTx("在这儿") : socialTx("计划中")} {a.arrival_date ? {a.arrival_date} : null}
  • ))}
) : null} {nearby.length ? (

{socialTx("继续逛")}

{socialTx("附近 / 下一站")}

{nearby.map((n) => ( {n.cover ? ( // eslint-disable-next-line @next/next/no-img-element ) : ( {n.emoji} )}
{n.emoji} {n.name} {n.vibe}
))}
) : null}
); }