1+ import { useEffect } from 'react' ;
12import {
23 Flex ,
34 LinkBox ,
@@ -9,27 +10,37 @@ import {
910 Text ,
1011 Link ,
1112 Box ,
13+ Menu ,
14+ MenuButton ,
15+ Portal ,
16+ MenuList ,
17+ MenuItem ,
1218} from '@chakra-ui/react' ;
1319import {
1420 BubbleIcon ,
1521 Code as CodigaCode ,
1622 CodeContent ,
1723 CopyIcon ,
24+ PencilIcon ,
1825 useToast ,
1926} from '@codiga/components' ;
20- import { useEffect } from 'react' ;
27+
28+ import { getSnippetUrl } from '../../utils/urlUtils' ;
2129import useCodeView , { CodeViewsType } from '../../hooks/useCodeView' ;
2230import { APP_URL } from '../../lib/config' ;
2331import { AssistantRecipeWithStats } from '../../types/assistantTypes' ;
2432import { decodeIndent } from '../../utils/codeUtils' ;
2533import CodeViewToggler from './CodeViewToggler' ;
34+ import { useUser } from '../UserContext' ;
2635
2736type CodeProps = {
2837 recipe : AssistantRecipeWithStats ;
2938} ;
3039
3140export default function Code ( { recipe } : CodeProps ) {
3241 const toast = useToast ( ) ;
42+ const { id : userId } = useUser ( ) ;
43+
3344 const [ codeView , setCodeView ] = useCodeView ( 'preview' ) ;
3445
3546 const neutral100 = useToken ( 'colors' , 'neutral.100' ) ;
@@ -138,6 +149,7 @@ export default function Code({ recipe }: CodeProps) {
138149 h = "32px"
139150 minW = "32px"
140151 p = "space_8"
152+ _hover = { { textDecor : 'none' } }
141153 icon = {
142154 < Flex gridGap = "space_4" alignItems = "center" >
143155 < BubbleIcon />
@@ -149,6 +161,53 @@ export default function Code({ recipe }: CodeProps) {
149161 aria-label = "Comment on Snippet"
150162 />
151163 </ 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+ ) }
152211 </ Flex >
153212
154213 < CodeContent
0 commit comments