- {
- chat_functions.current && chat_functions.current.platform !== 'Wllama' &&
-
- {
- hide_pending ?
-
:
-
+
+ { conversation.map(({role, content}, idx) => {
+ return (
+
+ )
+ }) }
+
+
+
> :
Please select a conversation or start a new one.
}
diff --git a/src/components/chat/Ticket.jsx b/src/components/chat/Ticket.jsx
index dd8afe8..9db8a9f 100644
--- a/src/components/chat/Ticket.jsx
+++ b/src/components/chat/Ticket.jsx
@@ -1,10 +1,20 @@
-export default function Ticket({ title, info, selectChat, is_selected }) {
+import { XLg } from "react-bootstrap-icons";
+
+export default function Ticket({ title, info, selectChat, is_selected, deleteHistory }) {
+
return (
selectChat(info)}
>
{ title }
+ {
+ evt.stopPropagation();
+ deleteHistory({ uid: info.uid, title })
+ }}
+ />
)
}
\ No newline at end of file
diff --git a/src/components/chat/Tickets.jsx b/src/components/chat/Tickets.jsx
index d91491b..2e019de 100644
--- a/src/components/chat/Tickets.jsx
+++ b/src/components/chat/Tickets.jsx
@@ -3,14 +3,14 @@ import Ticket from "./Ticket";
import useIDB from "../../utils/idb";
import { genRandomID } from "../../utils/tools";
-export default function Tickets({selectChat, current_chat, history, setHistory}) {
+export default function Tickets({selectChat, current_chat, history, setHistory, deleteHistory}) {
const idb = useIDB();
async function syncHistory() {
const history = await idb.getAll('chat-history')
history.sort((a, b)=>b.updatedAt - a.updatedAt)
- setHistory(history)
+ setHistory(history.map(e=>{return {...e, client: null}}))
}
async function startNewConversation() {
@@ -27,7 +27,7 @@ export default function Tickets({selectChat, current_chat, history, setHistory})
const new_conv_info = await idb.getByID('chat-history', conv_id);
new_conv_info &&
setHistory([
- new_conv_info,
+ {...new_conv_info, client: null},
...history
])
selectChat(new_conv_info)
@@ -50,9 +50,10 @@ export default function Tickets({selectChat, current_chat, history, setHistory})
const { title, uid } = elem;
return (
)
diff --git a/src/components/chat/index.jsx b/src/components/chat/index.jsx
index 2320190..a6a3116 100644
--- a/src/components/chat/index.jsx
+++ b/src/components/chat/index.jsx
@@ -1,11 +1,16 @@
-import { useState } from "react";
+import { useEffect, useRef, useState } from "react";
import Tickets from "./Tickets";
import Conversation from "./Conversation";
+import useIDB from "../../utils/idb";
export default function Chat() {
const [chat, selectChat] = useState({});
const [history, setHistory] = useState([]);
+ const idb = useIDB();
+ const dialogRef = useRef(null);
+ const [showConfirm, toggleConfirm] = useState(false);
+ const [conv_to_delete, requestDelete] = useState(null);
function updateChatClient(client) {
selectChat({
@@ -19,10 +24,54 @@ export default function Chat() {
setHistory(history_cp);
}
+ function resetRequestDelete() {
+ requestDelete(null);
+ toggleConfirm(false);
+ }
+
+ async function deleteHistory() {
+ if(!conv_to_delete) return;
+
+ const {uid} = conv_to_delete;
+ await idb.deleteOne("chat-history", [{uid}]);
+ await idb.deleteAll("messages", [{'history-uid': uid}]);
+ setHistory(history.filter(e=>e.uid !== uid));
+ uid === chat.uid && selectChat({});
+ resetRequestDelete();
+ }
+
+ useEffect(()=>{
+ if(dialogRef.current) {
+ if(showConfirm) dialogRef.current.showModal();
+ else dialogRef.current.close();
+ }
+ }, [showConfirm])
+
+ useEffect(()=>{
+ conv_to_delete && toggleConfirm(true);
+ }, [conv_to_delete])
+
return (
-
+
+
)
}
\ No newline at end of file