add import/export (#71)

This commit is contained in:
Mckay Wrigley authored and GitHub committed 2023-03-22 08:10:00 -06:00
1 parent 972a5aff23
commit f0c575b40d
6 files changed
+91 -5

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
import { Conversation } from "@/types";
export const exportConversations = () => {
const history = localStorage.getItem("conversationHistory");
if (!history) return;
const blob = new Blob([history], { type: "application/json" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.download = "chatbot_ui_history.json";
link.href = url;
link.style.display = "none";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
};
export const importConversations = (conversations: Conversation[]) => {
localStorage.setItem("conversationHistory", JSON.stringify(conversations));
};