1- import { forwardRef } from 'react' ;
1+ import { forwardRef , useCallback , useRef , useState } from 'react' ;
22import type { MDEditorProps } from '@uiw/react-md-editor/src/Types' ;
33import { RefMDEditor } from '@uiw/react-md-editor/src/Editor' ;
44import { useCopilotAction , useCopilotReadable } from '@copilotkit/react-core' ;
55import { CopilotTextarea } from '@copilotkit/react-textarea' ;
66import clsx from 'clsx' ;
77import { useUser } from '@gitroom/frontend/components/layout/user.context' ;
8+ import { makeId } from '@gitroom/nestjs-libraries/services/make.is' ;
9+ import { Transforms } from 'slate' ;
10+ import EmojiPicker from 'emoji-picker-react' ;
11+ import { Theme } from 'emoji-picker-react' ;
812
913export const Editor = forwardRef <
1014 RefMDEditor ,
@@ -19,6 +23,10 @@ export const Editor = forwardRef<
1923 ref : React . ForwardedRef < RefMDEditor >
2024 ) => {
2125 const user = useUser ( ) ;
26+ const [ id ] = useState ( makeId ( 10 ) ) ;
27+ const newRef = useRef ( null ) ;
28+ const [ emojiPickerOpen , setEmojiPickerOpen ] = useState ( false ) ;
29+
2230 useCopilotReadable ( {
2331 description : 'Content of the post number ' + ( props . order + 1 ) ,
2432 value : props . value ,
@@ -38,24 +46,55 @@ export const Editor = forwardRef<
3846 } ,
3947 } ) ;
4048
49+ const addText = useCallback (
50+ ( emoji : string ) => {
51+ // @ts -ignore
52+ Transforms . insertText ( newRef ?. current ?. editor ! , emoji ) ;
53+ } ,
54+ [ props . value , id ]
55+ ) ;
56+
4157 return (
42- < div className = "relative bg-customColor2" >
43- < CopilotTextarea
44- disableBranding = { true }
45- className = { clsx (
46- '!min-h-40 !max-h-80 p-2 overflow-x-hidden scrollbar scrollbar-thumb-[#612AD5] bg-customColor2 outline-none'
47- ) }
48- value = { props . value }
49- onChange = { ( e ) => props ?. onChange ?.( e . target . value ) }
50- onPaste = { props . onPaste }
51- placeholder = "Write your reply..."
52- autosuggestionsConfig = { {
53- textareaPurpose : `Assist me in writing social media posts.` ,
54- chatApiConfigs : { } ,
55- disabled : ! user ?. tier ?. ai ,
56- } }
57- />
58- </ div >
58+ < >
59+ < div className = "flex justify-end -mt-[30px]" >
60+ < div
61+ className = "select-none cursor-pointer bg-customColor2 w-[40px] p-[5px] text-center rounded-tl-lg rounded-tr-lg"
62+ onClick = { ( ) => setEmojiPickerOpen ( ! emojiPickerOpen ) }
63+ >
64+ 😀
65+ </ div >
66+ </ div >
67+ < div className = "absolute z-[200] right-0" >
68+ < EmojiPicker
69+ theme = { localStorage . getItem ( 'mode' ) as Theme || Theme . DARK }
70+ onEmojiClick = { ( e ) => {
71+ addText ( e . emoji ) ;
72+ setEmojiPickerOpen ( false ) ;
73+ } }
74+ open = { emojiPickerOpen }
75+ />
76+ </ div >
77+ < div className = "relative bg-customColor2" id = { id } >
78+ < CopilotTextarea
79+ disableBranding = { true }
80+ ref = { newRef }
81+ className = { clsx (
82+ '!min-h-40 !max-h-80 p-2 overflow-x-hidden scrollbar scrollbar-thumb-[#612AD5] bg-customColor2 outline-none'
83+ ) }
84+ value = { props . value }
85+ onChange = { ( e ) => {
86+ props ?. onChange ?.( e . target . value ) ;
87+ } }
88+ onPaste = { props . onPaste }
89+ placeholder = "Write your reply..."
90+ autosuggestionsConfig = { {
91+ textareaPurpose : `Assist me in writing social media posts.` ,
92+ chatApiConfigs : { } ,
93+ disabled : ! user ?. tier ?. ai ,
94+ } }
95+ />
96+ </ div >
97+ </ >
5998 ) ;
6099 }
61100) ;
0 commit comments