Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit e930764

Browse files
feat: added more dropdown and edit snippet button
1 parent f3df6be commit e930764

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

src/renderer/components/Code/Code.tsx

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useEffect } from 'react';
12
import {
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';
1319
import {
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';
2129
import useCodeView, { CodeViewsType } from '../../hooks/useCodeView';
2230
import { APP_URL } from '../../lib/config';
2331
import { AssistantRecipeWithStats } from '../../types/assistantTypes';
2432
import { decodeIndent } from '../../utils/codeUtils';
2533
import CodeViewToggler from './CodeViewToggler';
34+
import { useUser } from '../UserContext';
2635

2736
type CodeProps = {
2837
recipe: AssistantRecipeWithStats;
2938
};
3039

3140
export 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

src/renderer/utils/urlUtils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ export const getCookbookUrl = (id: number) => {
44
return `${APP_URL}/assistant/cookbook/${id}/view`;
55
};
66

7-
export const getSnippetUrl = (id: number) => {
8-
return `${APP_URL}/assistant/snippet/${id}/view`;
7+
export const getSnippetUrl: (id: number, page?: 'view' | 'edit') => string = (
8+
id,
9+
page = 'view'
10+
) => {
11+
return `${APP_URL}/assistant/snippet/${id}/${page}`;
912
};
1013

1114
export const getUserUrl = (slug: string) => {

0 commit comments

Comments
 (0)