feat: i18n (i18next + react-i18next) zh/en + hydration fixes
- i18next + react-i18next: zh/en locales, language detection (localStorage > navigator > zh), settings language switcher - Components i18n'd: Navbar, Feed, NewPost, Modals, SettingsPage, SettingsProfile, AccountSecurity, RecoveryCodes - Fix hydration mismatch (spinner restart): forum name via cookie (Server Component reads cookie, SSR outputs name, no inline script DOM injection); remove createPortal in RecoveryCodes modal; i18n sync init (initImmediate) so SSR/CSR text matches - LoadingScreen: React-state name rendering (no script-injected nodes) - Fix double spinner in Feed; DM icon emoji → SVG in ConversationList # Conflicts: # components/AppProvider.js # components/NewPost.js
This commit is contained in:
1 parent
024b678ad3
commit
1934edebd5
20 files changed
+600
-169
No files matched your search
@@ -0,0 +1,64 @@
|
||||
'use client';
|
||||
|
||||
// 主页客户端组件:SPA 视图调度 (feed/post/new/admin/settings/messages)
|
||||
import { useState } from 'react';
|
||||
import AppProvider, { useApp } from '@/components/AppProvider';
|
||||
import Navbar from '@/components/Navbar';
|
||||
import Sidebar from '@/components/Sidebar';
|
||||
import Feed from '@/components/Feed';
|
||||
import PostDetail from '@/components/PostDetail';
|
||||
import NewPost from '@/components/NewPost';
|
||||
import AdminPage from '@/components/AdminPage';
|
||||
import SettingsPage from '@/components/SettingsPage';
|
||||
import UserProfile from '@/components/UserProfile';
|
||||
import CustomPage from '@/components/CustomPage';
|
||||
import MessagesPage from '@/components/MessagesPage';
|
||||
import ChatManager from '@/components/chat/ChatManager';
|
||||
import Modals from '@/components/Modals';
|
||||
import LoadingScreen from '@/components/LoadingScreen';
|
||||
|
||||
function HomeInner() {
|
||||
const { view, currentPostId, currentUsername, currentPageName, ready, forumName, forumNameLoaded } = useApp();
|
||||
const [modal, setModal] = useState(null); // null | login | register | report
|
||||
const [reportPostId, setReportPostId] = useState(null);
|
||||
|
||||
const openModal = (m) => setModal(m);
|
||||
const openReport = (postId) => { setReportPostId(postId); setModal('report'); };
|
||||
|
||||
// 初始化未完成:显示全屏加载页,避免未加载完的界面闪烁
|
||||
if (!ready) {
|
||||
return <LoadingScreen forumName={forumName} forumNameLoaded={forumNameLoaded} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="app-fade-in">
|
||||
<Navbar onOpenModal={openModal} />
|
||||
<ChatManager />
|
||||
<div className="app-container">
|
||||
<Sidebar />
|
||||
<Feed onOpenModal={openModal} onReport={openReport} />
|
||||
</div>
|
||||
|
||||
{/* 独立页面 */}
|
||||
<div style={{ display: view !== 'feed' ? 'block' : 'none' }}>
|
||||
{view === 'post' && currentPostId && <PostDetail postId={currentPostId} />}
|
||||
{view === 'user' && currentUsername && <UserProfile username={currentUsername} />}
|
||||
{view === 'custom' && currentPageName && <CustomPage pageName={currentPageName} />}
|
||||
{view === 'new' && <NewPost />}
|
||||
{view === 'admin' && <AdminPage />}
|
||||
{view === 'settings' && <SettingsPage />}
|
||||
{view === 'messages' && <MessagesPage />}
|
||||
</div>
|
||||
|
||||
<Modals modal={modal} onClose={() => setModal(null)} reportPostId={reportPostId} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function HomeClient({ cachedName = '' }) {
|
||||
return (
|
||||
<AppProvider cachedName={cachedName}>
|
||||
<HomeInner />
|
||||
</AppProvider>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user