fix: polish forum navigation and interface states

This commit is contained in:
lezi-fun committed 2026-08-11 15:25:05 +08:00
1 parent 0933220c70
commit 6947cdaf36
33 files changed
+1615 -360

No files matched your search

+4 -2
View File
@@ -7,6 +7,7 @@ import { useApp } from '../AppProvider';
import { Icon } from '../Icons';
import ConversationList from './ConversationList';
import ChatWindow from './ChatWindow';
import { useToast } from '../Toast';
// 私信按钮(含未读 badge),渲染在导航栏内
export function DMButton() {
@@ -101,15 +102,16 @@ export default function ChatManager() {
// 供其他组件调用的打开私信(通过自定义事件桥接)
export function useOpenPrivateChat() {
const { currentUser } = useApp();
const { toast } = useToast();
const open = async (otherUserId, otherUsername) => {
if (!currentUser) { alert('请先登录'); return; }
if (!currentUser) { toast('请先登录', 'warning'); return; }
try {
const result = await API.getOrCreateConversation(otherUserId);
window.dispatchEvent(new CustomEvent('forumlify-open-chat', {
detail: { conversationId: result.id, otherUserId, otherUsername },
}));
} catch (err) {
alert('打开私信失败:' + err.message);
toast('打开私信失败:' + err.message, 'error');
}
};
return open;
+6 -3
View File
@@ -4,6 +4,8 @@
import { useEffect, useState, useRef, useCallback } from 'react';
import { API } from '@/lib/api';
import { useApp } from '../AppProvider';
import { Icon } from '../Icons';
import { useToast } from '../Toast';
function avatar(username) {
return 'https://ui-avatars.com/api/?name=' + encodeURIComponent(username || 'U') +
@@ -12,6 +14,7 @@ function avatar(username) {
export default function ChatWindow({ conversationId, otherUserId, otherUsername, onClose, onRefreshList }) {
const { currentUser } = useApp();
const { toast } = useToast();
const [messages, setMessages] = useState(null);
const [content, setContent] = useState('');
const containerRef = useRef(null);
@@ -47,7 +50,7 @@ export default function ChatWindow({ conversationId, otherUserId, otherUsername,
load();
onRefreshList();
} catch (err) {
alert('发送失败:' + err.message);
toast('发送失败:' + err.message, 'error');
}
};
@@ -56,7 +59,7 @@ export default function ChatWindow({ conversationId, otherUserId, otherUsername,
<div className="modal-content" style={{ display: 'flex', flexDirection: 'column', height: '70vh', maxHeight: '70vh', padding: 0, overflow: 'hidden' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '16px 20px', borderBottom: '1px solid var(--border)' }}>
<span id="chatTitle" style={{ fontWeight: 600, fontSize: 16 }}>{otherUsername}</span>
<span className="close" onClick={onClose} style={{ fontSize: 24, cursor: 'pointer', color: 'var(--text-light)', lineHeight: 1 }}>&times;</span>
<span className="close" onClick={onClose} style={{ cursor: 'pointer', color: 'var(--text-light)', lineHeight: 1 }}><Icon name="close" size={20} /></span>
</div>
<div id="chatMessages" ref={containerRef} style={{ flex: 1, overflowY: 'auto', padding: 16, minHeight: 0 }}>
{messages === null ? (
@@ -83,7 +86,7 @@ export default function ChatWindow({ conversationId, otherUserId, otherUsername,
{m.content}
</div>
<div style={{ fontSize: 11, color: 'var(--text-light)', marginTop: 4, textAlign: isMine ? 'right' : 'left' }}>
{time} {isMine ? (m.is_read ? '✓✓' : '✓') : ''}
{time} {isMine && <Icon name="success" size={10} aria-label={m.is_read ? '已读' : '已发送'} />}
</div>
</div>
</div>
+1 -1
View File
@@ -26,7 +26,7 @@ export default function ConversationList({ onOpenChat, onClose }) {
<div className="modal-content" style={{ display: 'flex', flexDirection: 'column', height: '70vh', maxHeight: '70vh', padding: 0, overflow: 'hidden' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '16px 20px', borderBottom: '1px solid var(--border)' }}>
<h2 style={{ fontSize: 18, margin: 0 }}><Icon name="message" size={18} style={{ verticalAlign: -3, marginRight: 6 }} /> 私信</h2>
<span className="close" onClick={onClose} style={{ fontSize: 24, cursor: 'pointer', color: 'var(--text-light)', lineHeight: 1 }}>&times;</span>
<span className="close" onClick={onClose} style={{ cursor: 'pointer', color: 'var(--text-light)', lineHeight: 1 }}><Icon name="close" size={20} /></span>
</div>
<div id="messageListContent" style={{ flex: 1, overflowY: 'auto', padding: 0 }}>
{conversations === null ? (