import { Button, Modal, Stack, Textarea, TextInput, ThemeIcon, Tooltip, } from "@mantine/core"; import { useDisclosure } from "@mantine/hooks"; import { notifications } from "@mantine/notifications"; import { IconPlaylistAdd, IconPlus } from "@tabler/icons-react"; import { nanoid } from "nanoid"; import { useEffect, useState } from "react"; import { db } from "../db"; export function CreatePromptModal({ content }: { content?: string }) { const [opened, { open, close }] = useDisclosure(false); const [submitting, setSubmitting] = useState(false); const [value, setValue] = useState(""); const [title, setTitle] = useState(""); useEffect(() => { setValue(content ?? ""); }, [content]); return ( <>
{ try { setSubmitting(true); event.preventDefault(); const id = nanoid(); db.prompts.add({ id, title, content: value, createdAt: new Date(), }); notifications.show({ title: "Saved", message: "Prompt created", }); close(); } catch (error: any) { if (error.toJSON().message === "Network Error") { notifications.show({ title: "Error", color: "red", message: "No internet connection.", }); } else { notifications.show({ title: "Error", color: "red", message: "Your OpenAI Key is invalid.", }); } } finally { setSubmitting(false); } }} > setTitle(event.currentTarget.value)} formNoValidate data-autofocus />