-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[ChatDraft]: adding chat draft UI (#48)
* feat[ChatDraft]: adding chat draft UI * feat(ChatDraft): change to make chat ui better * feat(ChatDraft): refactor unnecessary code * feat(ChatDraft): rename quill modules and formats * fix: prettier issue * feat(ChatDraft): position add to draft button
- Loading branch information
1 parent
d876353
commit d29df65
Showing
5 changed files
with
183 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
"use client"; | ||
import React, { useEffect, useRef } from "react"; | ||
import Drawer from "./ui/Drawer"; | ||
import { Button } from "./ui/Button"; | ||
import ReactQuill from "react-quill"; | ||
import { BookTextIcon } from "lucide-react"; | ||
|
||
interface IProps { | ||
draft: string; | ||
isOpen?: boolean; | ||
onCancel: () => void; | ||
onSubmit: (data: string) => void; | ||
} | ||
|
||
const quill_modules = { | ||
toolbar: [ | ||
[{ header: [1, 2, false] }], | ||
["bold", "italic", "underline", "strike", "blockquote"], | ||
[ | ||
{ list: "ordered" }, | ||
{ list: "bullet" }, | ||
{ indent: "-1" }, | ||
{ indent: "+1" }, | ||
], | ||
["link", "image"], | ||
["clean"], | ||
], | ||
}; | ||
|
||
const quill_formats = [ | ||
"header", | ||
"bold", | ||
"italic", | ||
"underline", | ||
"strike", | ||
"blockquote", | ||
"list", | ||
"bullet", | ||
"indent", | ||
"link", | ||
"image", | ||
]; | ||
|
||
const ChatDraftDrawer = ({ | ||
isOpen = true, | ||
draft, | ||
onSubmit, | ||
onCancel, | ||
}: IProps) => { | ||
const quillRef = useRef<ReactQuill | null>(null); | ||
|
||
useEffect(() => { | ||
if (quillRef.current) { | ||
const editor = quillRef.current.getEditor(); | ||
const editorContainer = editor.root; | ||
if (editorContainer) { | ||
editorContainer.scrollTop = editorContainer.scrollHeight; | ||
} | ||
} | ||
}, [draft]); | ||
|
||
return ( | ||
<Drawer isOpen={isOpen} onClose={onCancel} title="Draft Chat"> | ||
<div className="flex flex-col h-full"> | ||
<ReactQuill | ||
ref={quillRef} | ||
theme="snow" | ||
value={draft} | ||
onChange={onSubmit} | ||
modules={quill_modules} | ||
formats={quill_formats} | ||
/> | ||
<div className="sticky bottom-0 bg-white pb-4"> | ||
<div className="flex gap-2"> | ||
<Button | ||
// onClick={onSubmit} | ||
className="mt-4 px-4 py-2 bg-primary text-white rounded hover:bg-primary-dark" | ||
> | ||
<BookTextIcon className="inline-block mr-2" size={16} /> | ||
Rewrite with AI | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
</Drawer> | ||
); | ||
}; | ||
|
||
export default ChatDraftDrawer; |
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