2023-02-05 19:41:24 -05:00
|
|
|
import React from 'react';
|
2023-02-07 16:22:35 -05:00
|
|
|
import { useSelector } from 'react-redux';
|
2023-02-05 19:41:24 -05:00
|
|
|
|
2023-02-08 00:02:29 -05:00
|
|
|
export default function Message({ sender, text, last = false, error = false }) {
|
2023-02-07 16:22:35 -05:00
|
|
|
const { isSubmitting } = useSelector((state) => state.submit);
|
2023-02-06 18:25:11 -05:00
|
|
|
const props = {
|
|
|
|
|
className:
|
|
|
|
|
'group w-full border-b border-black/10 text-gray-800 dark:border-gray-900/50 dark:bg-gray-800 dark:text-gray-100'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (sender === 'GPT') {
|
|
|
|
|
props.className =
|
|
|
|
|
'group w-full border-b border-black/10 bg-gray-100 text-gray-800 dark:border-gray-900/50 dark:bg-[#444654] dark:text-gray-100';
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-05 19:41:24 -05:00
|
|
|
return (
|
2023-02-06 18:25:11 -05:00
|
|
|
<div {...props}>
|
|
|
|
|
<div className="m-auto flex gap-4 p-4 text-base md:max-w-2xl md:gap-6 md:py-6 lg:max-w-2xl lg:px-0 xl:max-w-3xl">
|
|
|
|
|
<strong className="relative flex w-[30px] flex-col items-end">{sender}:</strong>
|
|
|
|
|
<div className="relative flex w-[calc(100%-50px)] flex-col gap-1 whitespace-pre-wrap md:gap-3 lg:w-[calc(100%-115px)]">
|
2023-02-08 00:02:29 -05:00
|
|
|
<div className="flex flex-grow flex-col gap-3">
|
|
|
|
|
{!!error ? (
|
|
|
|
|
<div className="flex flex min-h-[20px] flex-row flex-col items-start gap-4 gap-2 whitespace-pre-wrap text-red-500">
|
|
|
|
|
<div className="rounded-md border border-red-500 bg-red-500/10 py-2 px-3 text-sm text-gray-600 dark:text-gray-100">
|
|
|
|
|
{text}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<span>
|
|
|
|
|
{text}
|
|
|
|
|
{isSubmitting && last && sender === 'GPT' && <span className="blink">█</span>}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2023-02-06 18:25:11 -05:00
|
|
|
</div>
|
2023-02-05 19:41:24 -05:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|