From fc197ea41a20d7c4ae86dc5b0307a440caa27d12 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Mon, 22 Sep 2025 23:05:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E6=8B=89=E5=88=B0=E6=9C=80?= =?UTF-8?q?=E9=A0=82=E9=83=A8=E5=8A=A0=E8=BC=89=E6=9B=B4=E5=A4=9A=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/ui/chat/ChatFragment.tsx | 41 ++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/client/ui/chat/ChatFragment.tsx b/client/ui/chat/ChatFragment.tsx index 5b73c03..7afca48 100644 --- a/client/ui/chat/ChatFragment.tsx +++ b/client/ui/chat/ChatFragment.tsx @@ -50,11 +50,11 @@ export default function ChatFragment({ target, ...props }: Args) { if (checkApiSuccessOrSncakbar(re, "拉取歷史記錄失敗")) return const returnMsgs = (re.data!.messages as Message[]).reverse() - if (returnMsgs.length == 0) - return snackbar({ - message: "已經沒有消息了哦~", - placement: 'top', - }) + if (returnMsgs.length == 0) { + setShowNoMoreMessagesTip(true) + setTimeout(() => setShowNoMoreMessagesTip(false), 1000) + return + } setMessagesList(returnMsgs.concat(messagesList)) if (page.current == 0) @@ -83,6 +83,8 @@ export default function ChatFragment({ target, ...props }: Args) { }) const inputRef = React.useRef(null) + const [showLoadingMoreMessagesTip, setShowLoadingMoreMessagesTip] = React.useState(false) + const [showNoMoreMessagesTip, setShowNoMoreMessagesTip] = React.useState(false) async function sendMessage() { const text = inputRef.current!.value @@ -124,14 +126,37 @@ export default function ChatFragment({ target, ...props }: Args) { display: tabItemSelected == "Chat" ? "flex" : "none", flexDirection: "column", height: "100%", + }} onScroll={async (e) => { + const scrollTop = (e.target as HTMLDivElement).scrollTop + if (scrollTop == 0 && !showLoadingMoreMessagesTip) { + setShowLoadingMoreMessagesTip(true) + await loadMore() + setShowLoadingMoreMessagesTip(false) + } }}>
- ()}>加載更多 +
+ + 加載中... +
+
+ 沒有更多消息啦~ +