From aedcef2320ac936d669b78d5aeb7e217a48880fd Mon Sep 17 00:00:00 2001 From: Andrei Canta Date: Tue, 21 Mar 2023 23:55:51 +0200 Subject: [PATCH] delete chats button --- src/components/DatabaseModal.tsx | 212 +++++++++--------- ...teDataModal.tsx => DeleteAllDataModal.tsx} | 20 +- src/components/DeleteChatsModal.tsx | 43 ++++ 3 files changed, 162 insertions(+), 113 deletions(-) rename src/components/{DeleteDataModal.tsx => DeleteAllDataModal.tsx} (87%) create mode 100644 src/components/DeleteChatsModal.tsx diff --git a/src/components/DatabaseModal.tsx b/src/components/DatabaseModal.tsx index a2dba60..513e641 100644 --- a/src/components/DatabaseModal.tsx +++ b/src/components/DatabaseModal.tsx @@ -1,4 +1,4 @@ -import { Button, Card, Flex, Group, Modal, Text } from "@mantine/core"; +import { Button, Card, Flex, Group, Modal, Stack, Text } from "@mantine/core"; import { useDisclosure } from "@mantine/hooks"; import { notifications } from "@mantine/notifications"; import { IconDatabaseExport, IconDatabaseImport } from "@tabler/icons-react"; @@ -6,7 +6,8 @@ import { useLiveQuery } from "dexie-react-hooks"; import download from "downloadjs"; import { cloneElement, ReactElement } from "react"; import { db } from "../db"; -import { DeleteDataModal } from "./DeleteDataModal"; +import { DeleteAllDataModal } from "./DeleteAllDataModal"; +import { DeleteChatsModal } from "./DeleteChatsModal"; export function DatabaseModal({ children }: { children: ReactElement }) { const [opened, { open, close }] = useDisclosure(false); @@ -31,108 +32,113 @@ export function DatabaseModal({ children }: { children: ReactElement }) { withinPortal keepMounted > - - - - {chatsCount} - - - Chats - - - - - {messagesCount} - - - Messages - - - - - {promptsCount} - - - Prompts - - - - - - { - const file = e.currentTarget.files?.[0]; - if (!file) return; - db.import(file, { - acceptNameDiff: true, - overwriteValues: true, - acceptMissingTables: true, - clearTablesBeforeImport: true, - }) - .then(() => { - notifications.show({ - title: "Importing data", - message: "Your data is being imported.", - }); - }) - .catch((error) => { - notifications.show({ - title: "Error", - color: "red", - message: "The file you selected is invalid", - }); + + + + + {chatsCount} + + + Chats + + + + + {messagesCount} + + + Messages + + + + + {promptsCount} + + + Prompts + + + + + - - + }} + > + Export Data + + { + const file = e.currentTarget.files?.[0]; + if (!file) return; + db.import(file, { + acceptNameDiff: true, + overwriteValues: true, + acceptMissingTables: true, + clearTablesBeforeImport: true, + }) + .then(() => { + notifications.show({ + title: "Importing data", + message: "Your data is being imported.", + }); + }) + .catch((error) => { + notifications.show({ + title: "Error", + color: "red", + message: "The file you selected is invalid", + }); + }); + }} + accept="application/json" + hidden + /> + + + + + + + ); diff --git a/src/components/DeleteDataModal.tsx b/src/components/DeleteAllDataModal.tsx similarity index 87% rename from src/components/DeleteDataModal.tsx rename to src/components/DeleteAllDataModal.tsx index bb44cb5..9b4cde6 100644 --- a/src/components/DeleteDataModal.tsx +++ b/src/components/DeleteAllDataModal.tsx @@ -3,15 +3,23 @@ import { useDisclosure } from "@mantine/hooks"; import { IconTrash } from "@tabler/icons-react"; import { db } from "../db"; -export function DeleteDataModal({ onOpen }: { onOpen: () => void }) { +export function DeleteAllDataModal({ onOpen }: { onOpen: () => void }) { const [opened, { open, close }] = useDisclosure(false, { onOpen }); return ( <> + @@ -29,14 +37,6 @@ export function DeleteDataModal({ onOpen }: { onOpen: () => void }) { - ); } diff --git a/src/components/DeleteChatsModal.tsx b/src/components/DeleteChatsModal.tsx new file mode 100644 index 0000000..e6d453a --- /dev/null +++ b/src/components/DeleteChatsModal.tsx @@ -0,0 +1,43 @@ +import { Button, Modal, Stack, Text } from "@mantine/core"; +import { useDisclosure } from "@mantine/hooks"; +import { IconTrash } from "@tabler/icons-react"; +import { db } from "../db"; + +export function DeleteChatsModal({ onOpen }: { onOpen: () => void }) { + const [opened, { open, close }] = useDisclosure(false, { onOpen }); + + return ( + <> + + + + Are you sure you want to delete your chats? + + + + + ); +}