"use client"; import { useCallback, useEffect, useState } from "react"; import { isChinaUser } from "is-china-user"; import { useLocale } from "~/components/locale-provider"; import styles from "./social-follow.module.css"; const DISMISS_KEY = "nomadro-social-dismiss"; const DISMISS_MS = 1000 * 60 * 60 * 24 * 7; // 7 days const SHOW_DELAY_MS = 4500; const X_URL = "https://x.com/nomadro"; /** Public WeChat OA QR — replace asset when brand QR updates */ export const WECHAT_OA_QR = "/wechat-oa-qr.png"; type Mode = "x" | "wechat"; function shouldShow(): boolean { try { const raw = localStorage.getItem(DISMISS_KEY); if (!raw) return true; const ts = Number(raw); if (!Number.isFinite(ts)) return true; return Date.now() - ts > DISMISS_MS; } catch { return true; } } /** 受控:加群 / 关注公众号二维码弹窗 */ export function WechatOaModal({ open, onClose, }: { open: boolean; onClose: () => void; }) { if (!open) return null; return (

保持连接

关注 公众号

获取出海导航、游民社群与会员更新,扫码即达。

{/* eslint-disable-next-line @next/next/no-img-element */} 微信公众号二维码 { (e.currentTarget as HTMLImageElement).style.display = "none"; const fallback = e.currentTarget.nextElementSibling; if (fallback instanceof HTMLElement) fallback.hidden = false; }} />
); } /** * 自动引导弹窗(默认关闭;远程 flags.socialFollowAuto === true 才延迟弹出) * 社区「加群」请用 WechatOaModal */ export function SocialFollowPrompt() { const { locale, ready } = useLocale(); const [open, setOpen] = useState(false); const [mode, setMode] = useState("wechat"); useEffect(() => { if (!ready) return; if (!shouldShow()) return; let cancelled = false; let timer = 0; const china = Boolean(isChinaUser()) || locale === "zh"; setMode(china ? "wechat" : "x"); void (async () => { let allow = false; try { const res = await fetch("/api/config", { cache: "no-store" }); const data = await res.json().catch(() => ({})); const flags = data?.config?.flags; // 双开关:总开关关 → 永不弹;自动弹须显式 true(默认 false,现网不变) allow = flags?.socialFollow !== false && flags?.socialFollowAuto === true; } catch { allow = false; } if (cancelled || !allow) return; timer = window.setTimeout(() => setOpen(true), SHOW_DELAY_MS); })(); return () => { cancelled = true; if (timer) window.clearTimeout(timer); }; }, [ready, locale]); const dismiss = useCallback(() => { setOpen(false); try { localStorage.setItem(DISMISS_KEY, String(Date.now())); } catch { /* ignore */ } }, []); if (!open) return null; const isZh = mode === "wechat"; return (

{isZh ? "保持连接" : "Stay in the loop"}

{isZh ? ( <> 关注 公众号 ) : ( <> Follow us on X )}

{isZh ? "获取出海导航、游民社群与会员更新,扫码即达。" : "Nomad nav, community drops, and VIP updates — one follow away."}

{isZh ? (
{/* eslint-disable-next-line @next/next/no-img-element */} 微信公众号二维码 { (e.currentTarget as HTMLImageElement).style.display = "none"; const fallback = e.currentTarget.nextElementSibling; if (fallback instanceof HTMLElement) fallback.hidden = false; }} />
) : ( 𝕏 Follow @nomadro )}
); }