file card ready
This commit is contained in:
parent
804c9a5a3e
commit
fcbc92f609
4 changed files with 69 additions and 18 deletions
|
|
@ -1,11 +1,10 @@
|
||||||
import {
|
import { ChatBubbleOvalLeftEllipsisIcon } from "@heroicons/react/24/outline";
|
||||||
ChatBubbleOvalLeftEllipsisIcon,
|
|
||||||
} from "@heroicons/react/24/outline";
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { ChatMessageType } from "../../../types/chat";
|
import { ChatMessageType } from "../../../types/chat";
|
||||||
import { classNames } from "../../../utils";
|
import { classNames } from "../../../utils";
|
||||||
import AiIcon from "../../../assets/Gooey Ring-5s-271px.svg"
|
import AiIcon from "../../../assets/Gooey Ring-5s-271px.svg";
|
||||||
import { UserIcon } from "@heroicons/react/24/solid";
|
import { UserIcon } from "@heroicons/react/24/solid";
|
||||||
|
import FileCard from "../fileComponent";
|
||||||
var Convert = require("ansi-to-html");
|
var Convert = require("ansi-to-html");
|
||||||
var convert = new Convert({ newline: true });
|
var convert = new Convert({ newline: true });
|
||||||
|
|
||||||
|
|
@ -20,7 +19,8 @@ export default function ChatMessage({ chat }: { chat: ChatMessageType }) {
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={classNames(
|
className={classNames(
|
||||||
"rounded-full w-9 h-9 flex items-center my-3 justify-center",chat.isSend?"bg-gray-200":"bg-gray-200"
|
"rounded-full w-9 h-9 flex items-center my-3 justify-center",
|
||||||
|
chat.isSend ? "bg-gray-200" : "bg-gray-200"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{!chat.isSend && <img className="scale-150" src={AiIcon} />}
|
{!chat.isSend && <img className="scale-150" src={AiIcon} />}
|
||||||
|
|
@ -28,9 +28,7 @@ export default function ChatMessage({ chat }: { chat: ChatMessageType }) {
|
||||||
</div>
|
</div>
|
||||||
{!chat.isSend ? (
|
{!chat.isSend ? (
|
||||||
<div className="w-full text-start flex items-center">
|
<div className="w-full text-start flex items-center">
|
||||||
<div
|
<div className=" relative text-start inline-block text-gray-600 text-sm font-normal">
|
||||||
className=" relative text-start inline-block text-gray-600 text-sm font-normal"
|
|
||||||
>
|
|
||||||
{hidden && chat.thought && chat.thought !== "" && (
|
{hidden && chat.thought && chat.thought !== "" && (
|
||||||
<div
|
<div
|
||||||
onClick={() => setHidden((prev) => !prev)}
|
onClick={() => setHidden((prev) => !prev)}
|
||||||
|
|
@ -42,17 +40,29 @@ export default function ChatMessage({ chat }: { chat: ChatMessageType }) {
|
||||||
{chat.thought && chat.thought !== "" && !hidden && (
|
{chat.thought && chat.thought !== "" && !hidden && (
|
||||||
<div
|
<div
|
||||||
onClick={() => setHidden((prev) => !prev)}
|
onClick={() => setHidden((prev) => !prev)}
|
||||||
className=" text-start inline-block w-full pb-3 pt-3 px-5 cursor-pointer"
|
className=" text-start inline-block rounded-md h-full
|
||||||
|
bg-white w-[95%] pb-3 pt-3 px-2 ml-3 cursor-pointer scrollbar-hide overflow-scroll"
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: convert.toHtml(chat.thought),
|
__html: convert.toHtml(chat.thought),
|
||||||
}}
|
}}
|
||||||
></div>
|
></div>
|
||||||
)}
|
)}
|
||||||
{chat.thought && chat.thought !== "" && !hidden && <br></br>}
|
{chat.thought && chat.thought !== "" && !hidden && <br></br>}
|
||||||
<div
|
<div className="w-full px-4 pb-3 pt-3 pr-8">
|
||||||
className="w-full rounded-b-md px-4 pb-3 pt-3 pr-8"
|
{chat.file ? (
|
||||||
>
|
<div></div>
|
||||||
|
) : (
|
||||||
|
<span>
|
||||||
{chat.message}
|
{chat.message}
|
||||||
|
<div className="my-2 w-full">
|
||||||
|
<FileCard
|
||||||
|
fileName={"FileType"}
|
||||||
|
fileType={"jpeg"}
|
||||||
|
content={""}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
34
src/frontend/src/modals/chatModal/fileComponent/index.tsx
Normal file
34
src/frontend/src/modals/chatModal/fileComponent/index.tsx
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
import { ArrowDownTrayIcon, CloudArrowDownIcon, DocumentIcon } from "@heroicons/react/24/outline";
|
||||||
|
|
||||||
|
export default function FileCard({ fileName, content, fileType }) {
|
||||||
|
const handleDownload = () => {
|
||||||
|
const blob = new Blob([content], { type: "application/octet-stream" });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.href = url;
|
||||||
|
link.download = fileName;
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
document.body.removeChild(link);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
onClick={handleDownload}
|
||||||
|
className="bg-gray-100 shadow rounded w-1/2 text-gray-700 hover:drop-shadow-lg px-2 py-2 flex justify-between items-center border border-gray-300"
|
||||||
|
>
|
||||||
|
<div className="flex gap-2 text-current items-center w-full mr-2">
|
||||||
|
{" "}
|
||||||
|
<DocumentIcon className="w-8 h-8" />
|
||||||
|
<div className="flex flex-col items-start">
|
||||||
|
{" "}
|
||||||
|
<div className="truncate text-sm text-current">{fileName}</div>
|
||||||
|
<div className="truncate text-xs text-gray-500">{fileType}</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<CloudArrowDownIcon className="w-6 h-6 text-current ml-auto" />
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -34,11 +34,15 @@ export default function ChatModal({
|
||||||
const addChatHistory = (
|
const addChatHistory = (
|
||||||
message: string,
|
message: string,
|
||||||
isSend: boolean,
|
isSend: boolean,
|
||||||
thought?: string
|
thought?: string,
|
||||||
|
file?:Blob
|
||||||
) => {
|
) => {
|
||||||
setChatHistory((old) => {
|
setChatHistory((old) => {
|
||||||
let newChat = _.cloneDeep(old);
|
let newChat = _.cloneDeep(old);
|
||||||
if (thought) {
|
if(file){
|
||||||
|
newChat.push({ message, isSend,file });
|
||||||
|
}
|
||||||
|
else if (thought) {
|
||||||
newChat.push({ message, isSend, thought });
|
newChat.push({ message, isSend, thought });
|
||||||
} else {
|
} else {
|
||||||
newChat.push({ message, isSend });
|
newChat.push({ message, isSend });
|
||||||
|
|
@ -82,8 +86,11 @@ export default function ChatModal({
|
||||||
addChatHistory(data.message, false, data.intermediate_steps);
|
addChatHistory(data.message, false, data.intermediate_steps);
|
||||||
setLockChat(false)
|
setLockChat(false)
|
||||||
}
|
}
|
||||||
|
if (data.type=="file"){
|
||||||
|
}
|
||||||
// Do something with the data received from the WebSocket
|
// Do something with the data received from the WebSocket
|
||||||
};
|
};
|
||||||
|
newWs.onclose=(e)=>{console.log(e.reason)}
|
||||||
setWs(newWs);
|
setWs(newWs);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,4 @@ import { ReactFlowInstance } from 'reactflow';
|
||||||
import { FlowType } from "../flow";
|
import { FlowType } from "../flow";
|
||||||
|
|
||||||
export type ChatType = {flow:FlowType,reactFlowInstance:ReactFlowInstance}
|
export type ChatType = {flow:FlowType,reactFlowInstance:ReactFlowInstance}
|
||||||
export type ChatMessageType = { message: string; isSend: boolean, thought?:string }
|
export type ChatMessageType = { message: string; isSend: boolean, thought?:string,file?:Blob }
|
||||||
Loading…
Add table
Add a link
Reference in a new issue