Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
"lucide-react": "^0.563.0",
"next": "^15.2.3",
"next-themes": "^0.4.6",
"pdfjs-dist": "5.4.296",
"postgres": "^3.4.4",
"radix-ui": "^1.4.3",
"react": "^19.0.0",
"react-day-picker": "^9.13.1",
"react-dom": "^19.0.0",
"react-hook-form": "^7.71.1",
"react-markdown": "^10.1.0",
"react-pdf": "^10.3.0",
"react-resizable-panels": "^4.6.2",
"react-shiki": "^0.9.1",
"rehype-katex": "^7.0.1",
Expand Down
197 changes: 195 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 35 additions & 1 deletion src/components/chat/chat-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ import { api } from "~/trpc/react";
interface ChatInterfaceProps {
noteId: string;
textContent?: string;
initialMessage?: string;
onMessageSent?: () => void;
}

export function ChatInterface({ noteId, textContent }: ChatInterfaceProps) {
export function ChatInterface({
noteId,
textContent,
initialMessage,
onMessageSent,
}: ChatInterfaceProps) {
const { data: history } = api.message.listByNoteId.useQuery({ noteId });
const utils = api.useUtils();

Expand Down Expand Up @@ -59,6 +66,33 @@ export function ChatInterface({ noteId, textContent }: ChatInterfaceProps) {
}
}, [history, setMessages, messages.length]);

// Handle initial message (e.g. from "Explain" button)
useEffect(() => {
if (initialMessage && !isLoading) {
void (async () => {
try {
// Send message immediately
await sendMessage({
parts: [
{
type: "text",
text: `Explain this: "${initialMessage}"`,
},
],
});

// Notify parent that message was sent (to clear pending state)
onMessageSent?.();

// Refresh stats after sending
await utils.stats.getMyStats.invalidate();
} catch (error) {
console.error("Error sending initial message:", error);
}
})();
}
}, [initialMessage, isLoading, sendMessage, onMessageSent, utils]);

// Scroll Logic
const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
Expand Down
Loading