diff --git a/src/components/chat/Conversation.jsx b/src/components/chat/Conversation.jsx
index 0fd7e06..8abdabb 100644
--- a/src/components/chat/Conversation.jsx
+++ b/src/components/chat/Conversation.jsx
@@ -1,19 +1,21 @@
import { useEffect, useRef, useState } from "react";
import ConversationBubble from "./ConversationBubble";
-import { FileImageFill, FileTextFill, Paperclip, Send, StopCircleFill } from 'react-bootstrap-icons';
+import { CheckCircle, FileImageFill, FileTextFill, Paperclip, Send, StopCircleFill, XCircle } from 'react-bootstrap-icons';
import useIDB from "../../utils/idb";
import { isModelLoaded, loadModel } from '../../utils/workers/worker'
import { getCompletionFunctions } from "../../utils/workers";
import { setClient as setAwsClient } from "../../utils/workers/aws-worker";
import { setClient as setOpenaiClient } from "../../utils/workers/openai-worker";
-export default function Conversation({ uid, client, updateClient }) {
+export default function Conversation({ uid, title, updateTitle, client, updateClient }) {
const [conversation, setConversation] = useState([]);
const [message, setMessage] = useState('');
const [pending_message, setPendingMessage] = useState('');
const [hide_pending, setHidePending] = useState(true);
const [upload_file, setUploadFile] = useState(null);
+ const [edit_title, toggleEditTitle] = useState(false);
+ const [edited_title, setEditedTitle] = useState(title);
const chat_functions = useRef(getCompletionFunctions());
const idb = useIDB();
@@ -108,6 +110,13 @@ export default function Conversation({ uid, client, updateClient }) {
setPendingMessage('');
setHidePending(true);
}
+
+ function submitUpdateTitle() {
+ if(edited_title && edited_title !== title) {
+ updateTitle(edited_title);
+ }
+ toggleEditTitle(false);
+ }
useEffect(()=>{
uid && getConversationByUid();
@@ -123,7 +132,11 @@ export default function Conversation({ uid, client, updateClient }) {
}, [conversation, pending_message])
useEffect(()=>{
- if(!chat_functions.current) return;
+ setEditedTitle(title);
+ }, [title])
+
+ useEffect(()=>{
+ if(!chat_functions.current || !uid) return;
const platform = chat_functions.current.platform
if(platform) {
@@ -139,13 +152,24 @@ export default function Conversation({ uid, client, updateClient }) {
})()
}
// eslint-disable-next-line
- }, [client])
+ }, [uid])
return (
{
uid ?
<>
+
+ {
+ edit_title ?
+
:
+
toggleEditTitle(true)}>{ title }
+ }
+
{ conversation.map(({role, content}, idx) => {
return (
diff --git a/src/components/chat/index.jsx b/src/components/chat/index.jsx
index a6a3116..288007e 100644
--- a/src/components/chat/index.jsx
+++ b/src/components/chat/index.jsx
@@ -40,6 +40,20 @@ export default function Chat() {
resetRequestDelete();
}
+ async function updateTitle(title) {
+ await idb.updateOne("chat-history", {title}, [{uid: chat.uid}])
+
+ selectChat({
+ ...chat, title: title
+ })
+
+ let history_cp = [...history];
+ history_cp[
+ history_cp.findIndex(e=>e.uid === chat.uid)
+ ].title = title;
+ setHistory(history_cp);
+ }
+
useEffect(()=>{
if(dialogRef.current) {
if(showConfirm) dialogRef.current.showModal();
@@ -58,7 +72,11 @@ export default function Chat() {
setHistory={setHistory} history={history}
deleteHistory={requestDelete}
/>
-
+