-
Notifications
You must be signed in to change notification settings - Fork 0
feat: refactor home page #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| { | ||
| "recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"] | ||
| "recommendations": [ | ||
| "tauri-apps.tauri-vscode", | ||
| "rust-lang.rust-analyzer", | ||
| "github.copilot-chat" | ||
| ] | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,251 @@ | ||||||||
| import { useState, useRef, useEffect } from "react"; | ||||||||
| import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; | ||||||||
| import { Button } from "@/components/ui/button"; | ||||||||
| import { Input } from "@/components/ui/input"; | ||||||||
| import { ScrollArea } from "@/components/ui/scroll-area"; | ||||||||
| import { Avatar, AvatarFallback } from "@/components/ui/avatar"; | ||||||||
| import { | ||||||||
| Sparkles, | ||||||||
| Send, | ||||||||
| Loader2, | ||||||||
| User, | ||||||||
| Bot, | ||||||||
| MessageSquare, | ||||||||
| } from "lucide-react"; | ||||||||
| import { cn } from "@/lib/utils"; | ||||||||
|
|
||||||||
| interface Message { | ||||||||
| id: string; | ||||||||
| role: "user" | "assistant"; | ||||||||
| content: string; | ||||||||
| timestamp: Date; | ||||||||
| } | ||||||||
|
|
||||||||
| const INITIAL_MESSAGES: Message[] = [ | ||||||||
| { | ||||||||
| id: "1", | ||||||||
| role: "assistant", | ||||||||
| content: "你好!我是你的 AI 助手。有什么我可以帮助你的吗?", | ||||||||
| timestamp: new Date(), | ||||||||
| }, | ||||||||
| ]; | ||||||||
|
|
||||||||
| export function AiChatBox() { | ||||||||
| const [messages, setMessages] = useState<Message[]>(INITIAL_MESSAGES); | ||||||||
| const [input, setInput] = useState(""); | ||||||||
| const [isLoading, setIsLoading] = useState(false); | ||||||||
| const scrollRef = useRef<HTMLDivElement>(null); | ||||||||
|
|
||||||||
| // Auto scroll to bottom when new messages arrive | ||||||||
| useEffect(() => { | ||||||||
| if (scrollRef.current) { | ||||||||
| scrollRef.current.scrollTop = scrollRef.current.scrollHeight; | ||||||||
| } | ||||||||
| }, [messages]); | ||||||||
|
|
||||||||
| const handleSend = async () => { | ||||||||
| if (!input.trim() || isLoading) return; | ||||||||
|
|
||||||||
| const userMessage: Message = { | ||||||||
| id: Date.now().toString(), | ||||||||
| role: "user", | ||||||||
| content: input.trim(), | ||||||||
| timestamp: new Date(), | ||||||||
| }; | ||||||||
|
|
||||||||
| setMessages((prev) => [...prev, userMessage]); | ||||||||
| setInput(""); | ||||||||
| setIsLoading(true); | ||||||||
|
|
||||||||
| // Simulate AI response | ||||||||
| setTimeout(() => { | ||||||||
| const aiMessage: Message = { | ||||||||
| id: (Date.now() + 1).toString(), | ||||||||
|
Comment on lines
+50
to
+63
|
||||||||
| role: "assistant", | ||||||||
| content: `我收到了你的消息:"${userMessage.content}"。这是一个模拟回复。`, | ||||||||
| timestamp: new Date(), | ||||||||
| }; | ||||||||
| setMessages((prev) => [...prev, aiMessage]); | ||||||||
| setIsLoading(false); | ||||||||
| }, 1000); | ||||||||
| }; | ||||||||
|
Comment on lines
+60
to
+71
|
||||||||
|
|
||||||||
| const handleKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||||||||
| if (e.key === "Enter" && !e.shiftKey) { | ||||||||
| e.preventDefault(); | ||||||||
| handleSend(); | ||||||||
| } | ||||||||
| }; | ||||||||
|
|
||||||||
| return ( | ||||||||
| <Card className="overflow-hidden border-border/50 bg-background hover:shadow-lg transition-shadow duration-300"> | ||||||||
| <CardHeader className="pb-3"> | ||||||||
| <CardTitle className="flex items-center gap-2 text-base"> | ||||||||
| <div className="p-1.5 bg-primary/10 rounded-lg"> | ||||||||
| <Sparkles size={18} className="text-primary" /> | ||||||||
| </div> | ||||||||
| <span className="font-semibold text-foreground">AI 助手</span> | ||||||||
| </CardTitle> | ||||||||
| <p className="text-xs text-muted-foreground mt-0.5"> | ||||||||
| 随时为你提供帮助和建议 | ||||||||
| </p> | ||||||||
| </CardHeader> | ||||||||
|
|
||||||||
| <CardContent className="space-y-3 px-6 pb-4"> | ||||||||
| {/* Messages Area */} | ||||||||
| <ScrollArea | ||||||||
| className="h-40 rounded-lg border border-border/50 bg-muted/20 p-3" | ||||||||
| ref={scrollRef} | ||||||||
|
Comment on lines
+96
to
+98
|
||||||||
| ref={scrollRef} | |
| ref={scrollRef} | |
| aria-label="AI 聊天消息历史" |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick action buttons set input values but don't automatically submit. This may create confusion as users might expect these buttons to immediately execute the action rather than just populating the input field.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,43 +4,72 @@ import { | |||||||||||||||||||||||||||||||||
| DropdownMenuContent, | ||||||||||||||||||||||||||||||||||
| DropdownMenuItem, | ||||||||||||||||||||||||||||||||||
| DropdownMenuTrigger, | ||||||||||||||||||||||||||||||||||
| DropdownMenuSeparator, | ||||||||||||||||||||||||||||||||||
| } from "@/components/ui/dropdown-menu"; | ||||||||||||||||||||||||||||||||||
| import { Separator } from "@/components/ui/separator"; | ||||||||||||||||||||||||||||||||||
| import { ChevronDown, Plus, Search } from "lucide-react"; | ||||||||||||||||||||||||||||||||||
| import { Input } from "@/components/ui/input"; | ||||||||||||||||||||||||||||||||||
| import { useState } from "react"; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export function HomeHeader() { | ||||||||||||||||||||||||||||||||||
| const [searchQuery, setSearchQuery] = useState(""); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const handleSearch = (e: React.FormEvent) => { | ||||||||||||||||||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||||||||||||||||||
| // TODO: 实现搜索逻辑 | ||||||||||||||||||||||||||||||||||
| console.log("Search:", searchQuery); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| console.log("Search:", searchQuery); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
暂时不需要关注
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The search functionality is not implemented (only logs to console). The TODO comment indicates this, but a placeholder that doesn't perform actual search functionality may confuse users if they interact with it.
| export function HomeHeader() { | |
| const [searchQuery, setSearchQuery] = useState(""); | |
| const handleSearch = (e: React.FormEvent) => { | |
| e.preventDefault(); | |
| // TODO: 实现搜索逻辑 | |
| console.log("Search:", searchQuery); | |
| export function HomeHeader({ onSearch }: { onSearch?: (query: string) => void }) { | |
| const [searchQuery, setSearchQuery] = useState(""); | |
| const handleSearch = (e: React.FormEvent) => { | |
| e.preventDefault(); | |
| if (onSearch) { | |
| onSearch(searchQuery); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding github.copilot-chat to the recommended extensions is unrelated to the home page refactoring described in the PR. This change should ideally be in a separate PR or the PR description should mention it. However, this is a minor organizational issue and doesn't affect functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要关注