Skip to content

Commit dec7c26

Browse files
committed
Merge branch 'anun/chat-gen' of https://github.com/CS3219-AY2425S1/cs3219-ay2425s1-project-g16 into anun/chat-gen
2 parents b66d9a1 + 4808a9e commit dec7c26

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

frontend/src/components/blocks/interview/ai-chat.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { type LanguageName } from '@uiw/codemirror-extensions-langs';
2+
import { MessageSquareIcon } from 'lucide-react';
23
import React, { useEffect, useRef, useState } from 'react';
34

5+
import { Button } from '@/components/ui/button';
46
import { sendChatMessage } from '@/services/collab-service';
57

68
import { ChatLayout } from './chat/chat-layout';
79
import { ChatMessageType } from './chat/chat-message';
810

11+
const STORAGE_KEY = 'ai_chat_history';
12+
913
interface AIChatProps {
1014
isOpen: boolean;
1115
onClose: () => void;
@@ -14,13 +18,16 @@ interface AIChatProps {
1418
questionDetails?: string;
1519
}
1620

17-
const STORAGE_KEY = 'ai_chat_history';
18-
1921
interface StoredChat {
2022
messages: ChatMessageType[];
2123
questionDetails: string;
2224
}
2325

26+
const prompts = [
27+
'Help me understand the code written.',
28+
'Give me some suggestions to solve the problem.',
29+
];
30+
2431
export const AIChat: React.FC<AIChatProps> = ({
2532
isOpen,
2633
onClose,
@@ -171,6 +178,25 @@ export const AIChat: React.FC<AIChatProps> = ({
171178
error={error}
172179
title='AI Assistant'
173180
onClearHistory={handleClearHistory}
181+
CustomPlaceHolderElem={({ onSend }) => (
182+
<div className='flex flex-col gap-6 text-center'>
183+
<MessageSquareIcon className='mx-auto size-12 opacity-50' />
184+
<p>No messages yet. Start a conversation, or use one of these prompts:</p>
185+
<div className='flex flex-wrap gap-4'>
186+
{prompts.map((value, index) => (
187+
<Button
188+
key={index}
189+
variant='outline'
190+
size='sm'
191+
className='rounded-xl'
192+
onClick={() => onSend(value)}
193+
>
194+
<span>{value}</span>
195+
</Button>
196+
))}
197+
</div>
198+
</div>
199+
)}
174200
/>
175201
);
176202
};

frontend/src/components/blocks/interview/chat/chat-layout.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { Loader2, MessageSquare, Send, Trash2, X } from 'lucide-react';
2-
import React, { ChangeEvent, KeyboardEvent, useEffect, useRef, useState } from 'react';
2+
import React, {
3+
ChangeEvent,
4+
KeyboardEvent,
5+
useEffect,
6+
useRef,
7+
useState,
8+
} from 'react';
39

410
import { Alert, AlertDescription } from '@/components/ui/alert';
511
import {
@@ -19,6 +25,10 @@ import { Textarea } from '@/components/ui/textarea';
1925

2026
import { ChatMessage, ChatMessageType } from './chat-message';
2127

28+
type CustomElemProps = {
29+
onSend: (message: string) => void;
30+
};
31+
2232
interface ChatLayoutProps {
2333
isOpen: boolean;
2434
onClose: () => void;
@@ -28,9 +38,10 @@ interface ChatLayoutProps {
2838
error: string | null;
2939
title: string;
3040
onClearHistory?: () => void;
41+
CustomPlaceHolderElem?: React.FC<CustomElemProps>;
3142
}
3243

33-
export const ChatLayout: React.FC<ChatLayoutProps> = ({
44+
export const ChatLayout = ({
3445
isOpen,
3546
onClose,
3647
messages,
@@ -39,7 +50,8 @@ export const ChatLayout: React.FC<ChatLayoutProps> = ({
3950
error,
4051
title,
4152
onClearHistory,
42-
}) => {
53+
CustomPlaceHolderElem,
54+
}: ChatLayoutProps) => {
4355
const [input, setInput] = useState<string>('');
4456
const inputRef = useRef<HTMLTextAreaElement>(null);
4557
const messagesEndRef = useRef<HTMLDivElement>(null);
@@ -132,8 +144,14 @@ export const ChatLayout: React.FC<ChatLayoutProps> = ({
132144
<ScrollArea id='chat-messages' className='h-full flex-1 overflow-y-auto p-4'>
133145
{messages.length === 0 && (
134146
<div className='flex h-full flex-col items-center justify-center text-gray-500'>
135-
<MessageSquare className='mb-4 size-12 opacity-50' />
136-
<p className='text-center'>No messages yet. Start a conversation!</p>
147+
{CustomPlaceHolderElem ? (
148+
<CustomPlaceHolderElem onSend={onSend} />
149+
) : (
150+
<>
151+
<MessageSquare className='mb-4 size-12 opacity-50' />
152+
<p className='text-center'>No messages yet. Start a conversation!</p>
153+
</>
154+
)}
137155
</div>
138156
)}
139157
{messages.map((msg, index) => (

frontend/src/components/ui/multi-select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ const MultiSelectorTrigger = forwardRef<HTMLDivElement, React.HTMLAttributes<HTM
221221
<div
222222
ref={ref}
223223
className={cn(
224-
'flex flex-wrap gap-1 p-1 py-2 ring-1 ring-muted whitespace-nowrap rounded-md text-sm shadow-sm rounded-lg bg-background border border-input placeholder:text',
224+
'flex flex-wrap gap-1 p-1 py-2 ring-1 ring-muted whitespace-nowrap text-sm shadow-sm rounded-lg bg-background border border-input placeholder:text',
225225
{
226226
'ring-1 focus-within:ring-ring': activeIndex === -1,
227227
},

frontend/src/lib/queries/question-details.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { getQuestionDetails } from '@/services/question-service';
21
import { queryOptions } from '@tanstack/react-query';
32

3+
import { getQuestionDetails } from '@/services/question-service';
4+
45
export const questionDetailsQuery = (id: number) =>
56
queryOptions({
67
queryKey: ['qn', 'details', id],

0 commit comments

Comments
 (0)