From 0d265e51ff347a33671af854c42789c2820be5b3 Mon Sep 17 00:00:00 2001 From: BetaHuhn Date: Wed, 30 Aug 2023 15:11:26 +0200 Subject: [PATCH] feat: customizable and reusable prompts --- src/components/CreatePromptModal.tsx | 99 ++++++++++++-- src/components/EditPromptModal.tsx | 76 ++++++++++- src/components/Layout.tsx | 110 +++++++++------- src/components/Prompts.tsx | 77 +++++------ src/config.json | 4 + src/db/index.ts | 16 ++- src/routes/ChatRoute.tsx | 187 +++++++++++++++++---------- src/utils/openai.ts | 14 ++ 8 files changed, 412 insertions(+), 171 deletions(-) diff --git a/src/components/CreatePromptModal.tsx b/src/components/CreatePromptModal.tsx index 04a6a17..b512219 100644 --- a/src/components/CreatePromptModal.tsx +++ b/src/components/CreatePromptModal.tsx @@ -2,6 +2,8 @@ import { ActionIcon, Button, Modal, + Select, + SimpleGrid, Stack, Textarea, TextInput, @@ -13,31 +15,45 @@ import { IconPlaylistAdd, IconPlus } from "@tabler/icons-react"; import { useEffect, useState } from "react"; import { detaDB, generateKey, Prompt } from "../db"; import { usePrompts } from "../hooks/contexts"; +import { config } from "../utils/config"; -export function CreatePromptModal({ content }: { content?: string }) { +export function CreatePromptModal({ content, title: titleProp, open: openProp }: { content?: string, title?: string, open?: boolean }) { const [opened, { open, close }] = useDisclosure(false); const [submitting, setSubmitting] = useState(false); const { setPrompts } = usePrompts() + const [writingCharacter, setWritingCharacter] = useState(null); + const [writingTone, setWritingTone] = useState(null); + const [writingStyle, setWritingStyle] = useState(null); + const [writingFormat, setWritingFormat] = useState(null); + const [value, setValue] = useState(""); const [title, setTitle] = useState(""); useEffect(() => { setValue(content ?? ""); - }, [content]); + setTitle(titleProp ?? ""); + if (openProp) { + open() + } + }, [content, titleProp, openProp]); return ( <> - {content ? ( - - - - - - ) : ( - + {!openProp && ( + <> + {content ? ( + + + + + + ) : ( + + )} + )}
setTitle(event.currentTarget.value)} formNoValidate data-autofocus /> + + + +