@@ -13,7 +13,7 @@ import { motion, AnimatePresence } from 'framer-motion';
1313import LoadingMessage from './LoadingMessage' ;
1414
1515const OutputBox = ( { handleTriggerRewrite, isGenerating } ) => {
16- const [ copied , setCopied ] = useState ( false ) ;
16+ const [ copied , setCopied ] = useState ( { } ) ;
1717 const [ selectedTabs , setSelectedTabs ] = useState ( [ ] ) ;
1818 const [ outputs , setOutputs ] = useState ( [ ] ) ;
1919 const [ error , setError ] = useState ( null ) ;
@@ -48,13 +48,16 @@ const OutputBox = ({ handleTriggerRewrite, isGenerating }) => {
4848 }
4949 } , [ isGenerating ] ) ;
5050
51- const handleCopy = ( text ) => {
51+ const handleCopy = ( text , id ) => {
52+ // Clean text before copying
53+ text = text . replace ( / < [ ^ > ] * > ? / gm, '' ) ;
5254 navigator . clipboard . writeText ( text ) ;
53- setCopied ( true ) ;
54- setTimeout ( ( ) => setCopied ( false ) , 2000 ) ;
55+ setCopied ( ( prevCopied ) => ( { ... prevCopied , [ id ] : true } ) ) ;
56+ setTimeout ( ( ) => setCopied ( ( prevCopied ) => ( { ... prevCopied , [ id ] : false } ) ) , 2000 ) ;
5557 } ;
5658
5759 const handleRewrite = ( text , id , type ) => {
60+ console . log ( 'Rewrite:' , text , id , type ) ;
5861 handleTriggerRewrite ( text , id , type ) ;
5962 } ;
6063
@@ -99,19 +102,46 @@ const OutputBox = ({ handleTriggerRewrite, isGenerating }) => {
99102 } }
100103 >
101104 < ListItemText primary = { query } />
102- < IconButton
103- edge = "end"
104- aria-label = "search"
105- onClick = { ( e ) => {
106- e . stopPropagation ( ) ;
107- handleSearch ( query ) ;
108- } }
109- style = { {
110- color : '#1A73E8' ,
105+ < Box
106+ sx = { {
107+ display : 'flex' ,
108+ flexDirection : 'column' ,
109+ alignItems : 'flex-end' ,
110+ gap : 1 ,
111111 } }
112112 >
113- < SearchIcon />
114- </ IconButton >
113+ < Tooltip title = "Search" >
114+ < IconButton
115+ edge = "end"
116+ aria-label = "search"
117+ onClick = { ( e ) => {
118+ e . stopPropagation ( ) ;
119+ handleSearch ( query ) ;
120+ } }
121+ style = { {
122+ color : '#1A73E8' ,
123+ } }
124+ >
125+ < SearchIcon />
126+ </ IconButton >
127+ </ Tooltip >
128+ { /* <Tooltip title="Copy to clipboard">
129+ <IconButton
130+ onClick={(e) => {
131+ e.stopPropagation();
132+ handleCopy(output.text, output.id);
133+ }}
134+ sx={{
135+ color: copied[output.id] ? 'green' : '#1A73E8',
136+ padding: 0.5,
137+ transition: 'color 0.3s',
138+ }}
139+ aria-label="copy"
140+ >
141+ {copied[output.id] ? <CheckIcon fontSize='small'/> : <ContentCopyIcon fontSize='small'/>}
142+ </IconButton>
143+ </Tooltip> */ }
144+ </ Box >
115145 </ ListItem >
116146 ) ) }
117147 </ List >
@@ -141,7 +171,7 @@ const OutputBox = ({ handleTriggerRewrite, isGenerating }) => {
141171 width : '100%' ,
142172 boxShadow : 3 ,
143173 border : '2px solid #1A73E8' ,
144- textAlign : 'center' ,
174+ // textAlign: 'center',
145175 } }
146176 >
147177 < Box
@@ -183,39 +213,49 @@ const OutputBox = ({ handleTriggerRewrite, isGenerating }) => {
183213 < InfoIcon fontSize = 'small' />
184214 </ IconButton >
185215 </ Tooltip >
186- < IconButton
187- onClick = { ( ) => handleCopy ( output . text ) }
188- sx = { {
189- color : copied ? 'green' : '#1A73E8' ,
190- padding : 0.5 ,
191- transition : 'color 0.3s' ,
192- } }
193- aria-label = "copy"
194- >
195- { copied ? < CheckIcon fontSize = 'small' /> : < ContentCopyIcon fontSize = 'small' /> }
196- </ IconButton >
197- < IconButton
198- onClick = { ( ) => handleRewrite ( output . text , output . id , output . type ) }
199- sx = { {
200- color : '#1A73E8' ,
201- padding : 0.5 ,
202- '&:hover' : { color : '#1558B0' } ,
203- } }
204- aria-label = "rewrite"
205- >
206- < EditIcon fontSize = 'small' />
207- </ IconButton >
208- < IconButton
209- onClick = { ( ) => handleDelete ( output . id ) }
210- sx = { {
211- color : '#1A73E8' ,
212- padding : 0.5 ,
213- '&:hover' : { color : 'red' } ,
214- } }
215- aria-label = "delete"
216- >
217- < DeleteIcon fontSize = 'small' />
218- </ IconButton >
216+ { output . type !== 'Search' && (
217+ < >
218+ < Tooltip title = "Copy to clipboard" >
219+ < IconButton
220+ onClick = { ( ) => handleCopy ( output . text , output . id ) }
221+ sx = { {
222+ color : copied [ output . id ] ? 'green' : '#1A73E8' ,
223+ padding : 0.5 ,
224+ transition : 'color 0.3s' ,
225+ } }
226+ aria-label = "copy"
227+ >
228+ { copied [ output . id ] ? < CheckIcon fontSize = 'small' /> : < ContentCopyIcon fontSize = 'small' /> }
229+ </ IconButton >
230+ </ Tooltip >
231+ < Tooltip title = "Rewrite" >
232+ < IconButton
233+ onClick = { ( ) => handleRewrite ( output . text , output . id , output . type ) }
234+ sx = { {
235+ color : '#1A73E8' ,
236+ padding : 0.5 ,
237+ '&:hover' : { color : '#1558B0' } ,
238+ } }
239+ aria-label = "rewrite"
240+ >
241+ < EditIcon fontSize = 'small' />
242+ </ IconButton >
243+ </ Tooltip >
244+ </ >
245+ ) }
246+ < Tooltip title = "Delete" >
247+ < IconButton
248+ onClick = { ( ) => handleDelete ( output . id ) }
249+ sx = { {
250+ color : '#1A73E8' ,
251+ padding : 0.5 ,
252+ '&:hover' : { color : 'red' } ,
253+ } }
254+ aria-label = "delete"
255+ >
256+ < DeleteIcon fontSize = 'small' />
257+ </ IconButton >
258+ </ Tooltip >
219259 </ Box >
220260 </ Box >
221261 { content }
0 commit comments