@@ -24,7 +24,9 @@ import { toast } from "sonner";
2424import Logo from "@/shared/components/Logo" ;
2525import { Separator } from "@/shared/components/ui/separator" ;
2626import { notFound } from "next/navigation" ;
27- import { MathJax , MathJaxContext } from "better-react-mathjax" ;
27+ import "katex/dist/katex.min.css" ;
28+ import rehypeKatex from "rehype-katex" ;
29+ import remarkMath from "remark-math" ;
2830
2931interface Message extends Tables < "Messages" > {
3032 user_id : string ;
@@ -242,95 +244,93 @@ const MessageArea = ({
242244 }
243245 />
244246 { /* <div className="mt-10 flex w-11/12 flex-col place-self-center rounded border p-4 text-gray-800 shadow dark:text-white"> */ }
245- < MathJaxContext >
246- < div className = "flex-1 overflow-auto" >
247- < ChatMessageList smooth className = "max-[500px]:px-0" >
248- { messages . flatMap ( ( message ) => {
249- const variant =
250- message . user_id === userAndClassData . userData . id
251- ? "sent"
252- : "received" ;
247+ < div className = "flex-1 overflow-auto" >
248+ < ChatMessageList smooth className = "max-[500px]:px-0" >
249+ { messages . flatMap ( ( message ) => {
250+ const variant =
251+ message . user_id === userAndClassData . userData . id
252+ ? "sent"
253+ : "received" ;
253254
254- // Format the timestamp
255- const messageTime = new Date ( message . created_at ) ;
256- const formattedTime = messageTime . toLocaleTimeString ( "en-US" , {
257- hour : "numeric" ,
258- minute : "numeric" ,
259- } ) ;
260- const formattedDay = new Date (
261- message . created_at
262- ) . toLocaleDateString ( "en-US" , {
263- month : "short" ,
264- day : "numeric" ,
265- year : "numeric" ,
266- } ) ;
267- const elements = [ ] ;
268- if (
269- ! previousMessageTime ||
270- isDifferentDay ( messageTime , previousMessageTime )
271- ) {
272- elements . push (
273- < div
274- key = { messageTime . getMilliseconds ( ) }
275- className = "flex items-center justify-center gap-4"
276- >
277- < Separator className = "w-[20%]" />
278- < span className = "text-muted-foreground" >
279- { formattedDay }
280- </ span >
281- < Separator className = "w-[20%]" />
282- </ div >
283- ) ;
284- }
285- previousMessageTime = messageTime ;
255+ // Format the timestamp
256+ const messageTime = new Date ( message . created_at ) ;
257+ const formattedTime = messageTime . toLocaleTimeString ( "en-US" , {
258+ hour : "numeric" ,
259+ minute : "numeric" ,
260+ } ) ;
261+ const formattedDay = new Date (
262+ message . created_at
263+ ) . toLocaleDateString ( "en-US" , {
264+ month : "short" ,
265+ day : "numeric" ,
266+ year : "numeric" ,
267+ } ) ;
268+ const elements = [ ] ;
269+ if (
270+ ! previousMessageTime ||
271+ isDifferentDay ( messageTime , previousMessageTime )
272+ ) {
286273 elements . push (
287- < ChatBubble
288- key = { message . id }
289- variant = { variant }
290- className = "max-w-[80%]"
274+ < div
275+ key = { messageTime . getMilliseconds ( ) }
276+ className = "flex items-center justify-center gap-4"
291277 >
292- { ! message ?. member_id ? (
293- < AIAvatar />
294- ) : (
295- < ChatBubbleAvatar src = { message . avatar_url ! } fallback = "Me" />
296- ) }
297- < div className = "flex flex-col" >
298- < div className = "mb-1 flex items-center gap-2 text-xs font-medium text-muted-foreground" >
299- { message ?. member_id
300- ? ( message . full_name ?? "Unknown" )
301- : AIFullNameFormatted ( "AI Assistant" ) } { " " }
302- • { formattedTime }
303- { message . is_ask && (
304- < span className = "inline-flex items-center rounded-full bg-purple-100 px-2 py-0.5 text-xs font-medium text-purple-800 dark:bg-purple-900 dark:text-purple-200" >
305- Ask LLM
306- </ span >
307- ) }
308- </ div >
309- < ChatBubbleMessage className = "p-2" variant = { variant } >
310- < MathJax
311- dynamic
312- hideUntilTypeset = "every"
313- className = "prose w-fit !whitespace-normal font-medium marker:text-inherit"
314- >
315- < ReactMarkdown >
316- { cleanMessage ( message . content ) }
317- </ ReactMarkdown >
318- </ MathJax >
319- </ ChatBubbleMessage >
320- </ div >
321- </ ChatBubble >
278+ < Separator className = "w-[20%]" />
279+ < span className = "text-muted-foreground" > { formattedDay } </ span >
280+ < Separator className = "w-[20%]" />
281+ </ div >
322282 ) ;
323- return elements ;
324- } ) }
325- { isLoading && (
326- < ChatBubble variant = "received" >
327- < AIAvatar />
328- < ChatBubbleMessage isLoading variant = "received" />
283+ }
284+ previousMessageTime = messageTime ;
285+ elements . push (
286+ < ChatBubble
287+ key = { message . id }
288+ variant = { variant }
289+ className = "max-w-[80%]"
290+ >
291+ { ! message ?. member_id ? (
292+ < AIAvatar />
293+ ) : (
294+ < ChatBubbleAvatar src = { message . avatar_url ! } fallback = "Me" />
295+ ) }
296+ < div className = "flex flex-col" >
297+ < div className = "mb-1 flex items-center gap-2 text-xs font-medium text-muted-foreground" >
298+ { message ?. member_id
299+ ? ( message . full_name ?? "Unknown" )
300+ : AIFullNameFormatted ( "AI Assistant" ) } { " " }
301+ • { formattedTime }
302+ { message . is_ask && (
303+ < span className = "inline-flex items-center rounded-full bg-purple-100 px-2 py-0.5 text-xs font-medium text-purple-800 dark:bg-purple-900 dark:text-purple-200" >
304+ Ask LLM
305+ </ span >
306+ ) }
307+ </ div >
308+ < ChatBubbleMessage
309+ className = "prose w-fit max-w-[50vw] !whitespace-normal p-2 font-medium marker:text-inherit"
310+ variant = { variant }
311+ >
312+ < ReactMarkdown
313+ remarkPlugins = { [
314+ [ remarkMath , { singleDollarTextMath : false } ] ,
315+ ] }
316+ rehypePlugins = { [ rehypeKatex ] }
317+ >
318+ { cleanMessage ( message . content ) }
319+ </ ReactMarkdown >
320+ </ ChatBubbleMessage >
321+ </ div >
329322 </ ChatBubble >
330- ) }
331- </ ChatMessageList >
332- </ div >
333- </ MathJaxContext >
323+ ) ;
324+ return elements ;
325+ } ) }
326+ { isLoading && (
327+ < ChatBubble variant = "received" >
328+ < AIAvatar />
329+ < ChatBubbleMessage isLoading variant = "received" />
330+ </ ChatBubble >
331+ ) }
332+ </ ChatMessageList >
333+ </ div >
334334 < div className = "relative mt-4 flex items-center justify-between gap-2 rounded-lg border bg-background p-1" >
335335 < ChatInput
336336 value = { messageBoxValue }
0 commit comments