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

Commit 143c058

Browse files
feat: added snippet/cookbook view pages
1 parent d0389a7 commit 143c058

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { useQuery } from '@apollo/client';
2+
import { useParams } from 'react-router-dom';
3+
import { Box, Flex, HStack, Text } from '@chakra-ui/react';
4+
5+
import { GET_COOKBOOK_RECIPES } from '../graphql/queries';
6+
import { GET_USER_RECIPES_VARIABLES } from '../graphql/variables';
7+
import ViewCookbookSnippetsError from '../components/ViewCookbookSnippets/ViewCookbookSnippetsError';
8+
import ViewCookbookSnippetsLoading from '../components/ViewCookbookSnippets/ViewCookbookSnippetsLoading';
9+
import ViewCookbookSnippetsEmpty from '../components/ViewCookbookSnippets/ViewCookbookSnippetsEmpty';
10+
import BackButton from '../components/BackButton';
11+
import FavoriteCookbook from '../components/Favorite/FavoriteCookbook';
12+
import AvatarAndName from '../components/AvatarAndName';
13+
import PrivacyAndVotes from '../components/PrivacyAndVotes';
14+
import FormattedDate from '../components/FormattedDate';
15+
import SnippetResults from '../components/SnippetResults/SnippetResults';
16+
17+
export default function ViewCookbookSnippets() {
18+
const params = useParams();
19+
20+
const { data, loading, error } = useQuery(GET_COOKBOOK_RECIPES, {
21+
variables: {
22+
cookbookId: Number(params.cookbookId),
23+
...GET_USER_RECIPES_VARIABLES,
24+
},
25+
});
26+
27+
const cookbook = data?.cookbook;
28+
29+
if (loading) {
30+
return <ViewCookbookSnippetsLoading />;
31+
}
32+
33+
if (error || !cookbook) {
34+
return <ViewCookbookSnippetsError />;
35+
}
36+
37+
return (
38+
<Box h="full">
39+
{/* INFO SECTION */}
40+
<HStack
41+
alignItems="center"
42+
bg="neutral.25"
43+
_dark={{ bg: 'base.dark' }}
44+
h="74px"
45+
w="full"
46+
spacing="space_16"
47+
>
48+
<BackButton />
49+
50+
<Flex alignItems="center" gridGap="space_8">
51+
<Text size="sm" fontWeight="bold" noOfLines={1}>
52+
{cookbook.name}
53+
</Text>
54+
<FavoriteCookbook
55+
isSubscribed={cookbook.isSubscribed}
56+
cookbookId={cookbook.id}
57+
/>
58+
</Flex>
59+
60+
<AvatarAndName owner={cookbook.owner} />
61+
62+
<PrivacyAndVotes
63+
isPublic={cookbook.isPublic}
64+
upvotes={cookbook.upvotes}
65+
downvotes={cookbook.downvotes}
66+
/>
67+
68+
<FormattedDate timestamp={cookbook.creationTimestampMs} />
69+
</HStack>
70+
71+
{!cookbook.recipes || cookbook.recipes.length === 0 ? (
72+
<ViewCookbookSnippetsEmpty />
73+
) : (
74+
<SnippetResults results={cookbook.recipes} />
75+
)}
76+
</Box>
77+
);
78+
}

src/renderer/pages/ViewSnippet.tsx

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { useParams } from 'react-router-dom';
2+
import { Box, Flex, HStack, Text } from '@chakra-ui/react';
3+
import { Logo, Tags } from '@codiga/components';
4+
import { useQuery } from '@apollo/client';
5+
6+
import { GET_RECIPE } from '../graphql/queries';
7+
import FavoriteSnippet from '../components/Favorite/FavoriteSnippet';
8+
import ViewSnippetError from '../components/ViewSnippet/ViewSnippetError';
9+
import ViewSnippetLoading from '../components/ViewSnippet/ViewSnippetLoading';
10+
import BackButton from '../components/BackButton';
11+
import PrivacyAndVotes from '../components/PrivacyAndVotes';
12+
import FormattedDate from '../components/FormattedDate';
13+
import AvatarAndName from '../components/AvatarAndName';
14+
import Code from '../components/Code/Code';
15+
16+
export default function ViewSnippet() {
17+
const params = useParams();
18+
19+
const { data, loading, error } = useQuery(GET_RECIPE, {
20+
variables: {
21+
recipeId: Number(params.snippetId),
22+
},
23+
});
24+
25+
const recipe = data?.recipe;
26+
27+
if (loading) {
28+
return <ViewSnippetLoading />;
29+
}
30+
31+
if (error || !recipe) {
32+
return <ViewSnippetError />;
33+
}
34+
35+
return (
36+
<Box h="full">
37+
{/* INFO SECTION */}
38+
<HStack
39+
alignItems="center"
40+
bg="neutral.25"
41+
_dark={{ bg: 'base.dark' }}
42+
h="74px"
43+
w="full"
44+
spacing="space_16"
45+
>
46+
<BackButton />
47+
48+
<Flex alignItems="center" gridGap="space_8">
49+
<Logo value={recipe.language} fullSize={false} logoSize={24} />
50+
<Text size="sm" fontWeight="bold" noOfLines={1}>
51+
{recipe.name}
52+
</Text>
53+
<FavoriteSnippet
54+
isSubscribed={recipe.isSubscribed}
55+
recipeId={recipe.id}
56+
/>
57+
</Flex>
58+
59+
<AvatarAndName owner={recipe.owner} />
60+
61+
<PrivacyAndVotes
62+
isPublic={recipe.isPublic}
63+
upvotes={recipe.upvotes}
64+
downvotes={recipe.downvotes}
65+
/>
66+
67+
<FormattedDate timestamp={recipe.creationTimestampMs} />
68+
69+
{recipe?.tags && recipe?.tags.length > 0 && (
70+
<Tags values={recipe?.tags || []} max={1} tagProps={{ size: 'sm' }} />
71+
)}
72+
</HStack>
73+
74+
{/* CODE */}
75+
<Code recipe={recipe} />
76+
</Box>
77+
);
78+
}

0 commit comments

Comments
 (0)