This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to save contexts and prompts (#17)
- Loading branch information
1 parent
a0a5117
commit 1d4a054
Showing
12 changed files
with
526 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,83 @@ | ||
import { Textarea } from "@mantine/core"; | ||
import { Modal, ScrollArea, Stack, Textarea } from "@mantine/core"; | ||
import { BiFolder, BiSave } from "react-icons/bi"; | ||
import TippedActionIcon from "./TippedActionIcon"; | ||
import { useDisclosure } from "@mantine/hooks"; | ||
import SaveContextModalBody from "./SavePromptModalBody"; | ||
import SavedContextsModalBody from "./SavedPromptsModalBody"; | ||
import usePersistence from "../hooks/usePersistence"; | ||
|
||
interface ContextInputProps { | ||
value: string; | ||
onChange: (value: string) => void; | ||
} | ||
|
||
export default ({ value, onChange }: ContextInputProps) => { | ||
const { | ||
persistence: { contexts }, | ||
} = usePersistence(); | ||
const [ | ||
showSaveContextModal, | ||
{ open: openSaveContextModal, close: closeSaveContextModal }, | ||
] = useDisclosure(false); | ||
const [ | ||
showSavedContextsModal, | ||
{ open: openSavedContextsModal, close: closeSavedContextsModal }, | ||
] = useDisclosure(false); | ||
|
||
return ( | ||
<Textarea | ||
value={value} | ||
onChange={(event) => onChange(event.currentTarget.value)} | ||
autosize | ||
minRows={3} | ||
maxRows={5} | ||
label="Context" | ||
/> | ||
<> | ||
<Textarea | ||
value={value} | ||
onChange={(event) => onChange(event.currentTarget.value)} | ||
autosize | ||
minRows={3} | ||
maxRows={5} | ||
label="Context" | ||
rightSection={ | ||
<Stack spacing="xs"> | ||
{contexts.length > 0 && ( | ||
<TippedActionIcon | ||
tip="Show Saved Contexts" | ||
onClick={openSavedContextsModal} | ||
> | ||
<BiFolder /> | ||
</TippedActionIcon> | ||
)} | ||
<TippedActionIcon | ||
tip="Save context" | ||
onClick={openSaveContextModal} | ||
> | ||
<BiSave /> | ||
</TippedActionIcon> | ||
</Stack> | ||
} | ||
/> | ||
<Modal | ||
opened={showSaveContextModal} | ||
onClose={closeSaveContextModal} | ||
title="Save Context" | ||
centered | ||
> | ||
<SaveContextModalBody | ||
mode="context" | ||
value={value} | ||
close={closeSaveContextModal} | ||
/> | ||
</Modal> | ||
<Modal | ||
opened={showSavedContextsModal} | ||
onClose={closeSavedContextsModal} | ||
title="Saved Contexts" | ||
centered | ||
scrollAreaComponent={ScrollArea.Autosize} | ||
size="lg" | ||
> | ||
<SavedContextsModalBody | ||
mode="context" | ||
onSelect={onChange} | ||
close={closeSavedContextsModal} | ||
/> | ||
</Modal> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.