1
+ import { useEffect } from 'react' ;
1
2
import {
2
3
Flex ,
3
4
LinkBox ,
@@ -9,27 +10,37 @@ import {
9
10
Text ,
10
11
Link ,
11
12
Box ,
13
+ Menu ,
14
+ MenuButton ,
15
+ Portal ,
16
+ MenuList ,
17
+ MenuItem ,
12
18
} from '@chakra-ui/react' ;
13
19
import {
14
20
BubbleIcon ,
15
21
Code as CodigaCode ,
16
22
CodeContent ,
17
23
CopyIcon ,
24
+ PencilIcon ,
18
25
useToast ,
19
26
} from '@codiga/components' ;
20
- import { useEffect } from 'react' ;
27
+
28
+ import { getSnippetUrl } from '../../utils/urlUtils' ;
21
29
import useCodeView , { CodeViewsType } from '../../hooks/useCodeView' ;
22
30
import { APP_URL } from '../../lib/config' ;
23
31
import { AssistantRecipeWithStats } from '../../types/assistantTypes' ;
24
32
import { decodeIndent } from '../../utils/codeUtils' ;
25
33
import CodeViewToggler from './CodeViewToggler' ;
34
+ import { useUser } from '../UserContext' ;
26
35
27
36
type CodeProps = {
28
37
recipe : AssistantRecipeWithStats ;
29
38
} ;
30
39
31
40
export default function Code ( { recipe } : CodeProps ) {
32
41
const toast = useToast ( ) ;
42
+ const { id : userId } = useUser ( ) ;
43
+
33
44
const [ codeView , setCodeView ] = useCodeView ( 'preview' ) ;
34
45
35
46
const neutral100 = useToken ( 'colors' , 'neutral.100' ) ;
@@ -138,6 +149,7 @@ export default function Code({ recipe }: CodeProps) {
138
149
h = "32px"
139
150
minW = "32px"
140
151
p = "space_8"
152
+ _hover = { { textDecor : 'none' } }
141
153
icon = {
142
154
< Flex gridGap = "space_4" alignItems = "center" >
143
155
< BubbleIcon />
@@ -149,6 +161,53 @@ export default function Code({ recipe }: CodeProps) {
149
161
aria-label = "Comment on Snippet"
150
162
/>
151
163
</ Tooltip >
164
+
165
+ { userId && recipe . owner && userId === recipe . owner . id && (
166
+ < Menu size = "sm" >
167
+ < MenuButton
168
+ as = { IconButton }
169
+ variant = "ghost"
170
+ h = "32px"
171
+ minW = "32px"
172
+ p = "space_8"
173
+ fontSize = "xx-small"
174
+ letterSpacing = "2px"
175
+ >
176
+ •••
177
+ </ MenuButton >
178
+ < Portal >
179
+ < MenuList
180
+ zIndex = "tooltip"
181
+ boxShadow = "base"
182
+ py = { 0 }
183
+ overflow = "hidden"
184
+ minW = "175px"
185
+ >
186
+ < MenuItem
187
+ as = { Link }
188
+ isExternal
189
+ href = { getSnippetUrl ( recipe . id , 'edit' ) }
190
+ _hover = { {
191
+ textDecor : 'none' ,
192
+ color : '#fff !important' ,
193
+ bg : 'base.rose' ,
194
+ } }
195
+ _focus = { { boxShadow : 'none' } }
196
+ >
197
+ < Text
198
+ size = "xs"
199
+ d = "flex"
200
+ alignItems = "center"
201
+ gridGap = "space_4"
202
+ color = "inherit !important"
203
+ >
204
+ < PencilIcon /> Edit Snippet
205
+ </ Text >
206
+ </ MenuItem >
207
+ </ MenuList >
208
+ </ Portal >
209
+ </ Menu >
210
+ ) }
152
211
</ Flex >
153
212
154
213
< CodeContent
0 commit comments