"use client"; import { useCallback, useEffect, useState } from "react"; import { usePathname } from "next/navigation"; import { VipLayout } from "@/app/vip/components/VipLayout"; import { COMMUNITY_CONFIG } from "@/config/community.config"; import { MemoExplorer } from "./components/MemoExplorer"; import { CommunitySidebar } from "./components/CommunitySidebar"; import styles from "./components/memos.module.css"; function getStorage(key: string): string | null { if (typeof window === "undefined") { return null; } return localStorage.getItem(key); } export default function CommunityLayout({ children }: { children: React.ReactNode }) { const pathname = usePathname(); const [userId, setUserId] = useState(null); const [isVip, setIsVip] = useState(false); const [userName, setUserName] = useState(null); const [userEmail, setUserEmail] = useState(null); const [showVipPrompt, setShowVipPrompt] = useState(false); useEffect(() => { const nextUserId = getStorage("userId") || getStorage("memosAccount"); const type = getStorage("paidType"); const name = getStorage("userName") || getStorage("userEmail"); const email = getStorage("userEmail"); setUserId(nextUserId || null); setIsVip(type === "vip"); setUserName(name || null); setUserEmail(email || null); }, []); const handleLogout = useCallback(async () => { const { pbLogout } = await import("@/app/lib/pocketbase"); await pbLogout(); if (typeof window !== "undefined") { localStorage.clear(); window.location.replace("/"); } }, []); if (!COMMUNITY_CONFIG.enabled) { return (

社区功能暂未开启。

); } return (
{showVipPrompt ? (

探索、归档和附件页仅对会员开放。

立即加入会员
) : null} {children}
); }