Skip to content

Commit

Permalink
fix: filter empty result
Browse files Browse the repository at this point in the history
  • Loading branch information
oae committed Oct 15, 2022
1 parent 6e9a6a4 commit 977b3d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
29 changes: 18 additions & 11 deletions src/components/addManga/steps/searchStep.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionIcon, LoadingOverlay, TextInput } from '@mantine/core';
import { ActionIcon, LoadingOverlay, Text, TextInput } from '@mantine/core';
import { UseFormReturnType } from '@mantine/form';
import { getHotkeyHandler } from '@mantine/hooks';
import { IconArrowRight, IconSearch } from '@tabler/icons';
Expand All @@ -13,6 +13,7 @@ export function SearchStep({ form }: { form: UseFormReturnType<FormType> }) {

const [loading, setLoading] = useState(false);
const [searchResult, setSearchResult] = useState<SearchResult>([]);
const [isEmptyResult, setIsEmptyResult] = useState(false);

const handleSearch = async () => {
form.validateField('query');
Expand All @@ -27,6 +28,8 @@ export function SearchStep({ form }: { form: UseFormReturnType<FormType> }) {
});
setLoading(false);

setIsEmptyResult(result.length === 0);

if (result) {
setSearchResult(result);
}
Expand Down Expand Up @@ -54,16 +57,20 @@ export function SearchStep({ form }: { form: UseFormReturnType<FormType> }) {
{...form.getInputProps('query')}
/>
<TextInput hidden {...form.getInputProps('mangaTitle')} />
<MangaSearchResult
items={searchResult}
onSelect={(selected) => {
if (selected) {
form.setFieldValue('mangaTitle', selected.title);
} else {
form.setFieldValue('mangaTitle', '');
}
}}
/>
{isEmptyResult ? (
<Text color="red">No result found...</Text>
) : (
<MangaSearchResult
items={searchResult}
onSelect={(selected) => {
if (selected) {
form.setFieldValue('mangaTitle', selected.title);
} else {
form.setFieldValue('mangaTitle', '');
}
}}
/>
)}
</>
);
}
2 changes: 1 addition & 1 deletion src/server/trpc/router/manga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const mangaRouter = t.router({
status: m.Metadata.Status,
title: m.Name,
cover: m.Metadata.Cover,
}));
})).filter((m) => !!m.title);
}),
remove: t.procedure
.input(
Expand Down

0 comments on commit 977b3d8

Please sign in to comment.