diff --git a/frontend/src/pages/GeneralSettings/Chats/index.jsx b/frontend/src/pages/GeneralSettings/Chats/index.jsx index d5b3d509..52a3c434 100644 --- a/frontend/src/pages/GeneralSettings/Chats/index.jsx +++ b/frontend/src/pages/GeneralSettings/Chats/index.jsx @@ -7,7 +7,7 @@ import useQuery from "@/hooks/useQuery"; import ChatRow from "./ChatRow"; import showToast from "@/utils/toast"; import System from "@/models/system"; -import { CaretDown, Download } from "@phosphor-icons/react"; +import { CaretDown, Download, Trash } from "@phosphor-icons/react"; import { saveAs } from "file-saver"; const exportOptions = { @@ -49,6 +49,12 @@ export default function WorkspaceChats() { const [showMenu, setShowMenu] = useState(false); const menuRef = useRef(); const openMenuButton = useRef(); + const query = useQuery(); + const [loading, setLoading] = useState(true); + const [chats, setChats] = useState([]); + const [offset, setOffset] = useState(Number(query.get("offset") || 0)); + const [canNext, setCanNext] = useState(false); + const handleDumpChats = async (exportType) => { const chats = await System.exportChats(exportType); if (!!chats) { @@ -62,6 +68,18 @@ export default function WorkspaceChats() { } }; + const handleClearAllChats = async () => { + if ( + !window.confirm( + `Are you sure you want to clear all chats?\n\nThis action is irreversible.` + ) + ) + return false; + await System.deleteChat(-1); + setChats([]); + showToast("Cleared all chats.", "success"); + }; + const toggleMenu = () => { setShowMenu(!showMenu); }; @@ -83,6 +101,16 @@ export default function WorkspaceChats() { }; }, []); + useEffect(() => { + async function fetchChats() { + const { chats: _chats, hasPages = false } = await System.chats(offset); + setChats(_chats); + setCanNext(hasPages); + setLoading(false); + } + fetchChats(); + }, [offset]); + return (
These are all the recorded chats and messages that have been sent by users ordered by their creation date.
-