From ad932d2dbd5ea18d1ba05e65723762705ef81c02 Mon Sep 17 00:00:00 2001 From: rathi Date: Mon, 9 Dec 2024 13:02:13 -0500 Subject: [PATCH] UI updates --- .env | 2 +- src/components/chat/Message.tsx | 173 +++++++++++++++++++++--- src/components/layout/Sidebar/index.tsx | 2 +- src/pages/dashboard/history.tsx | 2 +- 4 files changed, 156 insertions(+), 23 deletions(-) diff --git a/.env b/.env index 87e0f0b..d58fd21 100644 --- a/.env +++ b/.env @@ -2,7 +2,7 @@ VITE_SUPABASE_URL=https://nvatjthzedykhikmttot.supabase.co VITE_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im52YXRqdGh6ZWR5a2hpa210dG90Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzM1OTYxOTMsImV4cCI6MjA0OTE3MjE5M30.u4euR8U-XxxvOdLFmWJD2yrd4E_MPMt_X1yqRrDTF2I # N8N Configuration -VITE_N8N_WEBHOOK_URL=https://harivansh.app.n8n.cloud/webhook/chat-webhook +VITE_N8N_WEBHOOK_URL=https://harivansh.app.n8n.cloud/webhook-test/chat-webhook VITE_N8N_UPLOAD_WEBHOOK_URL=https://harivansh.app.n8n.cloud/webhook/upload-webhook # Google Drive Configuration diff --git a/src/components/chat/Message.tsx b/src/components/chat/Message.tsx index fe21b5e..120a3a4 100644 --- a/src/components/chat/Message.tsx +++ b/src/components/chat/Message.tsx @@ -4,11 +4,12 @@ import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import { Light as SyntaxHighlighter } from 'react-syntax-highlighter'; import { vs } from 'react-syntax-highlighter/dist/esm/styles/prism'; -import { Copy, Check } from 'lucide-react'; +import { Copy, Check, BookOpen, Link as LinkIcon, ThumbsUp, ThumbsDown } from 'lucide-react'; import { cn } from '../../lib/utils'; import { Button } from '../ui/Button'; import { Avatar, AvatarFallback } from '../ui/Avatar'; import { Tooltip } from '../ui/Tooltip'; +import { Separator } from '../ui/separator'; import type { ChatMessage } from '../../types/supabase'; import type { Components } from 'react-markdown'; @@ -21,8 +22,27 @@ interface CodeBlockProps { value: string; } +interface Citation { + text: string; + source: string; +} + +function extractCitations(content: string): { cleanContent: string; citations: Citation[] } { + const citationRegex = /\[([^\]]+)\]\(((?:(?!\)\[).)+)\)/g; + const citations: Citation[] = []; + const cleanContent = content.replace(citationRegex, (_, text, source) => { + citations.push({ text, source }); + return text; + }); + return { cleanContent, citations }; +} + export function Message({ message }: MessageProps) { const [copied, setCopied] = React.useState(false); + const [messageCopied, setMessageCopied] = React.useState(false); + const [isLiked, setIsLiked] = React.useState(false); + const [isDisliked, setIsDisliked] = React.useState(false); + const { cleanContent, citations } = extractCitations(message.content); const handleCopy = async (text: string) => { await navigator.clipboard.writeText(text); @@ -30,14 +50,35 @@ export function Message({ message }: MessageProps) { setTimeout(() => setCopied(false), 2000); }; + const handleMessageCopy = async () => { + try { + await navigator.clipboard.writeText(message.content); + setMessageCopied(true); + setTimeout(() => setMessageCopied(false), 2000); + } catch (err) { + console.error('Failed to copy message:', err); + } + }; + + const handleFeedback = (type: 'like' | 'dislike') => { + if (type === 'like') { + setIsLiked(!isLiked); + setIsDisliked(false); + } else { + setIsDisliked(!isDisliked); + setIsLiked(false); + } + // Here you could send feedback to your backend + }; + const CodeBlock = React.memo(({ language, value }: CodeBlockProps) => ( -
-
+
+
+
+ {language} + {value.split('\n').length} lines +
{value.replace(/\n$/, '')} @@ -66,7 +112,7 @@ export function Message({ message }: MessageProps) { if (!className) { return ( - + {children} ); @@ -75,51 +121,138 @@ export function Message({ message }: MessageProps) { return ; }; + const components: Components = { + code, + h1: ({ children }) => ( +

+ {children} +

+ ), + h2: ({ children }) => ( +

+ {children} +

+ ), + h3: ({ children }) => ( +

+ {children} +

+ ), + }; + return (
{message.role === 'assistant' && ( - + AI )} -
+
- {message.content} + {cleanContent} + + {message.role === 'assistant' && citations.length > 0 && ( + <> + +
+
+ + Sources +
+ {citations.map((citation, index) => ( +
+ + + {citation.text} - {citation.source} + +
+ ))} +
+ + )}
-
- {formatDistanceToNow(new Date(message.created_at), { addSuffix: true })} +
+ + {formatDistanceToNow(new Date(message.created_at), { addSuffix: true })} + + + {message.role === 'assistant' && ( +
+ + + + + + + + + +
+ )}
{message.role === 'user' && ( - + You diff --git a/src/components/layout/Sidebar/index.tsx b/src/components/layout/Sidebar/index.tsx index be5c40a..f38d0d0 100644 --- a/src/components/layout/Sidebar/index.tsx +++ b/src/components/layout/Sidebar/index.tsx @@ -16,7 +16,7 @@ const sidebarItems = [ }, { icon: History, - label: 'Study History', + label: 'Chat History', path: '/dashboard/history' }, { diff --git a/src/pages/dashboard/history.tsx b/src/pages/dashboard/history.tsx index 0accea2..0c01651 100644 --- a/src/pages/dashboard/history.tsx +++ b/src/pages/dashboard/history.tsx @@ -42,7 +42,7 @@ export default function StudyHistory() {
-

Study History

+

Chat History

View your past conversations