diff --git a/src/app/dashboard/[org]/[repo]/chat/ChatPage.tsx b/src/app/dashboard/[org]/[repo]/chat/ChatPage.tsx index 2227f38..2416927 100644 --- a/src/app/dashboard/[org]/[repo]/chat/ChatPage.tsx +++ b/src/app/dashboard/[org]/[repo]/chat/ChatPage.tsx @@ -5,6 +5,7 @@ import React, { useMemo } from "react"; import { Chat } from "./components/Chat"; import { api } from "~/trpc/react"; import LoadingIndicator from "../components/LoadingIndicator"; +import { useSearchParams } from 'next/navigation'; interface ChatPageProps { org: string; @@ -21,6 +22,10 @@ const ChatPage: React.FC = ({ org, repo }) => { repo, }); + const searchParams = useSearchParams(); + const filePath = searchParams.get('file_path'); + const selectedFilePath = filePath ? decodeURIComponent(filePath) : undefined; + const memoizedContextItems = useMemo( () => contextItems ?? [], [contextItems], @@ -40,6 +45,7 @@ const ChatPage: React.FC = ({ org, repo }) => { contextItems={memoizedContextItems} org={org} repo={repo} + selectedFilePath={selectedFilePath} /> ); diff --git a/src/app/dashboard/[org]/[repo]/chat/components/Chat.tsx b/src/app/dashboard/[org]/[repo]/chat/components/Chat.tsx index b16debf..1bbb1d8 100644 --- a/src/app/dashboard/[org]/[repo]/chat/components/Chat.tsx +++ b/src/app/dashboard/[org]/[repo]/chat/components/Chat.tsx @@ -22,6 +22,7 @@ interface ChatProps { contextItems: ContextItem[]; org: string; repo: string; + selectedFilePath?: string; } export interface CodeFile { @@ -44,7 +45,7 @@ const STARTING_MESSAGE = { "Hi, I'm JACoB. I can answer questions about your codebase. Ask me anything!", }; -export function Chat({ contextItems, org, repo }: ChatProps) { +export function Chat({ contextItems, org, repo, selectedFilePath }: ChatProps) { const [artifactContent, setArtifactContent] = useState(null); const [artifactFileName, setArtifactFileName] = useState(""); const [artifactLanguage, setArtifactLanguage] = useState(""); @@ -163,6 +164,18 @@ export function Chat({ contextItems, org, repo }: ChatProps) { } }, [codeContent]); + useEffect(() => { + if (selectedFilePath) { + const selectedFile = contextItems.find(item => item.file === selectedFilePath); + if (selectedFile) { + setSelectedFiles([selectedFilePath]); + void refetchCodeContent(); + } else { + toast.error("Selected file not found in the codebase context."); + } + } + }, [selectedFilePath, contextItems, refetchCodeContent]); + const handleSearchResultSelect = (filePath: string) => { setSelectedFiles([filePath]); void refetchCodeContent(); diff --git a/src/app/dashboard/[org]/[repo]/code-visualizer/codebase/CodebaseDetails.tsx b/src/app/dashboard/[org]/[repo]/code-visualizer/codebase/CodebaseDetails.tsx index 76f467f..eede6fa 100644 --- a/src/app/dashboard/[org]/[repo]/code-visualizer/codebase/CodebaseDetails.tsx +++ b/src/app/dashboard/[org]/[repo]/code-visualizer/codebase/CodebaseDetails.tsx @@ -10,6 +10,7 @@ import { faChevronDown, faCopy, faCheck, + faComment, } from "@fortawesome/free-solid-svg-icons"; import Mermaid from "./Mermaid"; import Markdown, { type Components } from "react-markdown"; @@ -25,6 +26,7 @@ import { } from "react-syntax-highlighter/dist/cjs/styles/prism"; import { faClipboard } from "@fortawesome/free-solid-svg-icons"; import { toast } from "react-toastify"; +import { useRouter } from 'next/navigation'; interface CodebaseDetailsProps { item: ContextItem; @@ -105,6 +107,7 @@ const CodebaseDetails: React.FC = ({ theme, }) => { const [copyStatus, setCopyStatus] = useState(false); + const router = useRouter(); const handleCopy = () => { navigator.clipboard @@ -118,6 +121,15 @@ const CodebaseDetails: React.FC = ({ }); }; + const handleSendToChat = () => { + if (item.file) { + const encodedFilePath = encodeURIComponent(item.file); + router.push(`/dashboard/${item.org}/${item.repo}/chat?file_path=${encodedFilePath}`); + } else { + toast.error("No file selected. Please select a file before sending to chat."); + } + }; + return (
@@ -187,6 +199,16 @@ const CodebaseDetails: React.FC = ({ ) : null}
+ +
+ +
); }; @@ -236,4 +258,4 @@ export const Section: React.FC<{ ); }; -export default CodebaseDetails; +export default CodebaseDetails; \ No newline at end of file