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

Commit f3df6be

Browse files
feat: added empty filtered states
1 parent b28ed55 commit f3df6be

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Button, Flex, Link } from '@chakra-ui/react';
2+
import { EmptyState } from '@codiga/components';
3+
import { useParams } from 'react-router-dom';
4+
import { APP_URL } from '../../lib/config';
5+
6+
type ViewCookbookSnippetsEmptyFilteredProps = {
7+
clearSearch: () => void;
8+
};
9+
10+
export default function ViewCookbookSnippetsEmptyFiltered({
11+
clearSearch,
12+
}: ViewCookbookSnippetsEmptyFilteredProps) {
13+
const params = useParams();
14+
15+
return (
16+
<EmptyState
17+
title="No snippets match that search"
18+
description="There are no snippets in this cookbook that match your search."
19+
illustration="empty"
20+
py="space_64"
21+
>
22+
<Flex gridGap="space_16">
23+
<Button variant="secondary" size="sm" onClick={clearSearch}>
24+
Clear Filters
25+
</Button>
26+
27+
<Link
28+
isExternal
29+
href={`${APP_URL}/assistant/snippet/create?cookbookId=${params.cookbookId}`}
30+
variant="primary"
31+
size="sm"
32+
>
33+
Add Snippet to Cookbook
34+
</Link>
35+
</Flex>
36+
</EmptyState>
37+
);
38+
}

src/renderer/pages/ViewCookbookSnippets.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-nested-ternary */
12
import { useState } from 'react';
23
import { useQuery } from '@apollo/client';
34
import { useParams } from 'react-router-dom';
@@ -10,6 +11,7 @@ import { PAGE_QUERY_POLL_INTERVAL_IN_MS } from '../lib/constants';
1011
import ViewCookbookSnippetsError from '../components/ViewCookbookSnippets/ViewCookbookSnippetsError';
1112
import ViewCookbookSnippetsLoading from '../components/ViewCookbookSnippets/ViewCookbookSnippetsLoading';
1213
import ViewCookbookSnippetsEmpty from '../components/ViewCookbookSnippets/ViewCookbookSnippetsEmpty';
14+
import ViewCookbookSnippetsEmptyFiltered from '../components/ViewCookbookSnippets/ViewCookbookSnippetsEmptyFiltered';
1315
import BackButton from '../components/BackButton';
1416
import FavoriteCookbook from '../components/Favorite/FavoriteCookbook';
1517
import AvatarAndName from '../components/AvatarAndName';
@@ -101,25 +103,28 @@ export default function ViewCookbookSnippets() {
101103

102104
<Flex w="full" flex={1} justifyContent="flex-end">
103105
<Input
104-
minWidth="200px"
106+
minWidth="100px"
105107
maxWidth="500px"
106108
justifySelf="flex-end"
107109
mr="space_16"
108-
placeholder="Search on this cookbook"
110+
placeholder="Search"
109111
value={searchTerm}
110112
onChange={(e) => setSearchTerm(e.target.value)}
111113
/>
112114
</Flex>
113115
</HStack>
114116
)}
115117

116-
{/* eslint-disable-next-line no-nested-ternary */}
117118
{cookbookSnippetLoading ? (
118119
<SnippetResultsLoading />
119-
) : snippets.length === 0 ? (
120-
<ViewCookbookSnippetsEmpty />
121-
) : (
120+
) : snippets.length > 0 ? (
122121
<SnippetResults results={snippets} />
122+
) : searchTerm ? (
123+
<ViewCookbookSnippetsEmptyFiltered
124+
clearSearch={() => setSearchTerm('')}
125+
/>
126+
) : (
127+
<ViewCookbookSnippetsEmpty />
123128
)}
124129
</Box>
125130
);

0 commit comments

Comments
 (0)