diff --git a/src/components/tabs/MarkdownTabPage/MarkdownTabPage.tsx b/src/components/tabs/MarkdownTabPage/MarkdownTabPage.tsx index 1adfff7..faea37c 100644 --- a/src/components/tabs/MarkdownTabPage/MarkdownTabPage.tsx +++ b/src/components/tabs/MarkdownTabPage/MarkdownTabPage.tsx @@ -29,7 +29,7 @@ export const MarkdownTabPage: React.FC = ({ return (
diff --git a/src/modules/home/HomePage.tsx b/src/modules/home/HomePage.tsx index 93a6f2f..b3dbc32 100644 --- a/src/modules/home/HomePage.tsx +++ b/src/modules/home/HomePage.tsx @@ -1,9 +1,5 @@ +import { ChatLayout } from './components/ChatLayout' + export const HomePage = () => { - return ( -
-

- 开始今天的工作吧! -

-
- ) + return } diff --git a/src/modules/home/components/ChatContent.tsx b/src/modules/home/components/ChatContent.tsx new file mode 100644 index 0000000..1fc98b3 --- /dev/null +++ b/src/modules/home/components/ChatContent.tsx @@ -0,0 +1,120 @@ +import { Send } from 'lucide-react' +import { useChatStore, type ChatMessage } from '@/stores/chatStore' +import { useState, useRef, useEffect } from 'react' + +const MessageItem = ({ message }: { message: ChatMessage }) => { + const isUser = message.role === 'user' + + return ( +
+
+
+ {isUser ? ( + 👤 + ) : ( + 🤖 + )} +
+
+ {message.content} +
+
+
+ ) +} + +export const ChatContent = () => { + const { currentChatId, chats, addMessage, updateChatTitle } = useChatStore() + const [input, setInput] = useState('') + const messagesEndRef = useRef(null) + + const currentChat = chats.find((c) => c.id === currentChatId) + const messages = currentChat?.messages ?? [] + + useEffect(() => { + messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }) + }, [messages.length]) + + const handleSend = () => { + if (!input.trim() || !currentChatId) return + + const userMessage: ChatMessage = { + id: Math.random().toString(36).substring(2, 15), + role: 'user', + content: input.trim(), + timestamp: Date.now(), + } + + addMessage(currentChatId, userMessage) + + if (messages.length === 0) { + const title = input.trim().slice(0, 20) + (input.trim().length > 20 ? '...' : '') + updateChatTitle(currentChatId, title) + } + + setInput('') + } + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter' && !e.shiftKey) { + e.preventDefault() + handleSend() + } + } + + return ( +
+
+ {messages.length === 0 ? ( +
+

+ 开始今天的工作吧! +

+
+ ) : ( +
+ {messages.map((msg) => ( + + ))} +
+
+ )} +
+ +
+
+
+