Skip to content

Commit 52f7e88

Browse files
committed
perf: 👌 优化 AI 对话 滚动底部逻辑
1 parent a77654b commit 52f7e88

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ NoteGen is a cross-platform `Markdown` note-taking application dedicated to usin
2424

2525
Recording:
2626

27-
![record](https://s2.loli.net/2025/04/14/NxhiWjMZT7RtusS.png)
27+
![record](https://github.com/user-attachments/assets/34f7fdc7-ebab-473f-ad8b-e2e93ed0f9e3)
2828

2929
Writing:
3030

docs/en/guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ NoteGen is a cross-platform `Markdown` note-taking application dedicated to usin
1313

1414
Recording:
1515

16-
![record](https://s2.loli.net/2025/04/14/NxhiWjMZT7RtusS.png)
16+
![record](https://github.com/user-attachments/assets/34f7fdc7-ebab-473f-ad8b-e2e93ed0f9e3)
1717

1818
Writing:
1919

docs/ja/guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ NoteGenは、AIを使用して記録と執筆を橋渡しし、断片化され
1313

1414
記録:
1515

16-
![record](https://s2.loli.net/2025/04/14/NxhiWjMZT7RtusS.png)
16+
![record](https://github.com/user-attachments/assets/34f7fdc7-ebab-473f-ad8b-e2e93ed0f9e3)
1717

1818
執筆:
1919

docs/zh/guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ NoteGen 是一款的跨端的 `Markdown` 笔记应用,致力于使用 AI 建
1515

1616
记录:
1717

18-
![record](https://s2.loli.net/2025/04/14/NxhiWjMZT7RtusS.png)
18+
![record](https://github.com/user-attachments/assets/34f7fdc7-ebab-473f-ad8b-e2e93ed0f9e3)
1919

2020
写作:
2121

src/app/core/record/chat/chat-content.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,31 @@ import useSyncStore from '@/stores/sync'
1515
import { Avatar, AvatarImage } from '@/components/ui/avatar'
1616
import ChatThinking from './chat-thinking'
1717
import { Separator } from '@/components/ui/separator'
18+
import { debounce } from 'lodash-es'
1819

1920
export default function ChatContent() {
2021
const { chats, init } = useChatStore()
2122
const { currentTagId } = useTagStore()
2223

23-
useEffect(() => {
24-
init(currentTagId)
25-
}, [currentTagId])
26-
27-
useEffect(() => {
24+
function scrollToBottom() {
2825
const md = document.querySelector('#chats-wrapper')
2926
if (md) {
3027
md.scroll(0, md.scrollHeight)
3128
setTimeout(() => {
3229
md.scroll(0, md.scrollHeight)
33-
}, 500)
30+
}, 1000)
3431
}
32+
}
33+
34+
// debounce
35+
const scrollToBottomDebounce = debounce(scrollToBottom, 500)
36+
37+
useEffect(() => {
38+
init(currentTagId)
39+
}, [currentTagId])
40+
41+
useEffect(() => {
42+
scrollToBottomDebounce()
3543
}, [chats])
3644

3745
return <div id="chats-wrapper" className="flex-1 overflow-y-auto overflow-x-hidden w-full flex flex-col items-end p-4 gap-6">

src/app/core/record/chat/chat-preview.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import useSettingStore from "@/stores/setting";
33
import { useEffect, useRef, useState } from 'react';
44
import { useTheme } from 'next-themes'
55
import useChatStore from '@/stores/chat';
6+
import { debounce } from 'lodash-es'
67

78
export default function ChatPreview({text}: {text: string}) {
89
const [id] = useState('preview-only');
@@ -26,8 +27,10 @@ export default function ChatPreview({text}: {text: string}) {
2627
}, 100);
2728
}
2829

30+
const bindPreviewLinkDebounce = debounce(bindPreviewLink, 1000)
31+
2932
useEffect(() => {
30-
bindPreviewLink()
33+
bindPreviewLinkDebounce()
3134
}, [chats])
3235

3336
useEffect(() => {

0 commit comments

Comments
 (0)