fix: navbar full-width layout
- Remove flex wrapper around Navbar that collapsed it to content width - Move DM button inside Navbar nav-right, ChatManager renders modals only - Navbar is a direct body child again, sticky + full width restored
This commit is contained in:
1 parent
ec50efea89
commit
60c21ae0a6
3 files changed
+37
-37
No files matched your search
+2
-6
@@ -26,12 +26,8 @@ function HomeInner() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
<Navbar onOpenModal={openModal} />
|
||||||
<Navbar onOpenModal={openModal} style={{ flex: 1 }} />
|
<ChatManager />
|
||||||
<div style={{ paddingRight: 16 }}>
|
|
||||||
<ChatManager />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="app" style={{ display: view === 'feed' ? 'flex' : 'none' }}>
|
<div id="app" style={{ display: view === 'feed' ? 'flex' : 'none' }}>
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
// 导航栏:论坛名、自定义页面链接、登录/注册、用户菜单、主题切换
|
// 导航栏:论坛名、自定义页面链接、登录/注册、私信、用户菜单、主题切换
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { useApp } from './AppProvider';
|
import { useApp } from './AppProvider';
|
||||||
import { Icon } from './Icons';
|
import { Icon } from './Icons';
|
||||||
import { API } from '@/lib/api';
|
import { API } from '@/lib/api';
|
||||||
|
import { DMButton } from './chat/ChatManager';
|
||||||
|
|
||||||
export default function Navbar({ onOpenModal }) {
|
export default function Navbar({ onOpenModal }) {
|
||||||
const { currentUser, forumName, theme, toggleTheme, navigate, openCustomPage, logout } = useApp();
|
const { currentUser, forumName, theme, toggleTheme, navigate, openCustomPage, logout } = useApp();
|
||||||
@@ -59,6 +60,7 @@ export default function Navbar({ onOpenModal }) {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="nav-right">
|
<div className="nav-right">
|
||||||
|
<DMButton />
|
||||||
<div id="userMenu">
|
<div id="userMenu">
|
||||||
{!currentUser ? (
|
{!currentUser ? (
|
||||||
<div id="authButtons">
|
<div id="authButtons">
|
||||||
|
|||||||
@@ -1,38 +1,55 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
// 私信管理器:会话列表 modal + 聊天窗口 modal + 未读 badge + openPrivateChat
|
// 私信管理器:会话列表 modal + 聊天窗口 modal + 未读 badge
|
||||||
import { useState, useEffect, useCallback } from 'react';
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
import { API } from '@/lib/api';
|
import { API } from '@/lib/api';
|
||||||
import { useApp } from '../AppProvider';
|
import { useApp } from '../AppProvider';
|
||||||
import ConversationList from './ConversationList';
|
import ConversationList from './ConversationList';
|
||||||
import ChatWindow from './ChatWindow';
|
import ChatWindow from './ChatWindow';
|
||||||
|
|
||||||
export default function ChatManager() {
|
// 私信按钮(含未读 badge),渲染在导航栏内
|
||||||
|
export function DMButton() {
|
||||||
const { currentUser } = useApp();
|
const { currentUser } = useApp();
|
||||||
const [listOpen, setListOpen] = useState(false);
|
|
||||||
const [chat, setChat] = useState(null); // {conversationId, otherUserId, otherUsername}
|
|
||||||
const [unread, setUnread] = useState(0);
|
const [unread, setUnread] = useState(0);
|
||||||
const [refreshKey, setRefreshKey] = useState(0);
|
|
||||||
|
|
||||||
const refreshList = useCallback(() => setRefreshKey((k) => k + 1), []);
|
|
||||||
|
|
||||||
// 未读 badge 轮询(30 秒 + 每次刷新)
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!currentUser) return;
|
if (!currentUser) { setUnread(0); return; }
|
||||||
const update = () => {
|
const update = () => {
|
||||||
API.getConversations()
|
API.getConversations()
|
||||||
.then((cs) => {
|
.then((cs) => setUnread((cs || []).reduce((s, c) => s + (c.unread_count || 0), 0)))
|
||||||
const total = (cs || []).reduce((s, c) => s + (c.unread_count || 0), 0);
|
|
||||||
setUnread(total);
|
|
||||||
})
|
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
update();
|
update();
|
||||||
const t = setInterval(update, 30000);
|
const t = setInterval(update, 30000);
|
||||||
return () => clearInterval(t);
|
return () => clearInterval(t);
|
||||||
}, [currentUser, refreshKey]);
|
}, [currentUser]);
|
||||||
|
|
||||||
// 监听其他组件发起的打开私信事件
|
return (
|
||||||
|
<button
|
||||||
|
className="nav-icon-btn"
|
||||||
|
title="私信"
|
||||||
|
style={{ position: 'relative', padding: '6px 8px', background: 'none', border: 'none', cursor: 'pointer', color: 'var(--text-secondary)', borderRadius: 4, display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}
|
||||||
|
onClick={() => window.dispatchEvent(new CustomEvent('forumlify-open-messages'))}
|
||||||
|
>
|
||||||
|
✉️
|
||||||
|
{unread > 0 && (
|
||||||
|
<span style={{ position: 'absolute', top: -2, right: -2, background: '#ef4444', color: '#fff', borderRadius: '50%', padding: '2px 6px', fontSize: 10, fontWeight: 600, minWidth: 18, textAlign: 'center', lineHeight: 1.4 }}>
|
||||||
|
{unread > 99 ? '99+' : unread}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 私信 modals 容器(会话列表 + 聊天窗口)
|
||||||
|
export default function ChatManager() {
|
||||||
|
const [listOpen, setListOpen] = useState(false);
|
||||||
|
const [chat, setChat] = useState(null); // {conversationId, otherUserId, otherUsername}
|
||||||
|
const [refreshKey, setRefreshKey] = useState(0);
|
||||||
|
|
||||||
|
const refreshList = useCallback(() => setRefreshKey((k) => k + 1), []);
|
||||||
|
|
||||||
|
// 监听事件:打开会话列表 / 打开聊天
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handler = (e) => {
|
const handler = (e) => {
|
||||||
setChat(e.detail);
|
setChat(e.detail);
|
||||||
@@ -59,21 +76,6 @@ export default function ChatManager() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* 导航栏私信按钮 + 未读 badge */}
|
|
||||||
<button
|
|
||||||
className="nav-icon-btn"
|
|
||||||
title="私信"
|
|
||||||
style={{ position: 'relative', padding: '6px 8px', background: 'none', border: 'none', cursor: 'pointer', color: 'var(--text-secondary)', borderRadius: 4, display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}
|
|
||||||
onClick={() => setListOpen(true)}
|
|
||||||
>
|
|
||||||
✉️
|
|
||||||
{unread > 0 && (
|
|
||||||
<span style={{ position: 'absolute', top: -2, right: -2, background: '#ef4444', color: '#fff', borderRadius: '50%', padding: '2px 6px', fontSize: 10, fontWeight: 600, minWidth: 18, textAlign: 'center', lineHeight: 1.4 }}>
|
|
||||||
{unread > 99 ? '99+' : unread}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{listOpen && (
|
{listOpen && (
|
||||||
<ConversationList
|
<ConversationList
|
||||||
onOpenChat={openChat}
|
onOpenChat={openChat}
|
||||||
|
|||||||
Reference in new issue
Block a user