fix chat ux and ai model
This commit is contained in:
@@ -84,6 +84,7 @@ function ChatPage() {
|
||||
const [convsLoading, setConvsLoading] = useState(false);
|
||||
const [closedExpanded, setClosedExpanded] = useState(false);
|
||||
const [selectedFile, setSelectedFile] = useState(null);
|
||||
const [switchingConv, setSwitchingConv] = useState(false);
|
||||
|
||||
const messagesEndRef = useRef(null);
|
||||
const messagesAreaRef = useRef(null);
|
||||
@@ -108,11 +109,14 @@ function ChatPage() {
|
||||
lastScrolledIdRef.current = lastMsg.id;
|
||||
const area = messagesAreaRef.current;
|
||||
if (!area) return;
|
||||
const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 80;
|
||||
if (nearBottom) {
|
||||
const isOwn = lastMsg.senderId === user?.id;
|
||||
if (isOwn) {
|
||||
area.scrollTop = area.scrollHeight;
|
||||
} else {
|
||||
const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 80;
|
||||
if (nearBottom) area.scrollTop = area.scrollHeight;
|
||||
}
|
||||
}, [messages]);
|
||||
}, [messages, user?.id]);
|
||||
|
||||
const fetchMessages = useCallback(async (convId) => {
|
||||
if (!token || !convId) return;
|
||||
@@ -416,10 +420,10 @@ function ChatPage() {
|
||||
if (stompRef.current) { stompRef.current.deactivate(); stompRef.current = null; }
|
||||
setMessages([]);
|
||||
setError(null);
|
||||
setLoadingConv(true);
|
||||
setSwitchingConv(true);
|
||||
await fetchConversation(convId);
|
||||
await fetchMessages(convId);
|
||||
setLoadingConv(false);
|
||||
setSwitchingConv(false);
|
||||
connectStomp(convId);
|
||||
router.replace(`/chat?id=${convId}`, { scroll: false });
|
||||
}
|
||||
@@ -640,6 +644,11 @@ function ChatPage() {
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{switchingConv && (
|
||||
<div style={{ textAlign: "center", padding: "1rem", color: "#aaa", fontSize: "0.85rem" }}>
|
||||
Loading messages…
|
||||
</div>
|
||||
)}
|
||||
<div ref={messagesEndRef} />
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user