From f6f7cdf7d1aad81d1b350707e42d5a031152cd2d Mon Sep 17 00:00:00 2001 From: Lucieo Date: Mon, 18 Sep 2023 16:18:42 +0200 Subject: [PATCH] Fix/no results search (#16) * Distinguish no bookmarks and / no search result * Unify wording * Hide controls if no search results * Fix issue with URLSearchParams --- src/app/(routes)/teams/[teamSlug]/page.tsx | 1 + .../bookmark/BookmarksListControls.tsx | 4 +- src/components/bookmark/BookmarksTeamList.tsx | 63 ++++++++----------- src/components/digests/SearchInput.tsx | 2 +- src/components/list/Pagination.tsx | 2 +- src/components/pages/DigestEditPage.tsx | 1 + src/components/pages/Team.tsx | 23 +++++-- 7 files changed, 50 insertions(+), 46 deletions(-) diff --git a/src/app/(routes)/teams/[teamSlug]/page.tsx b/src/app/(routes)/teams/[teamSlug]/page.tsx index b43d496..3a4813d 100644 --- a/src/app/(routes)/teams/[teamSlug]/page.tsx +++ b/src/app/(routes)/teams/[teamSlug]/page.tsx @@ -53,6 +53,7 @@ const TeamPage = async ({ params, searchParams }: TeamPageProps) => { linkCount={totalCount} bookmarks={bookmarks} digests={digests} + search={search} /> ); }; diff --git a/src/components/bookmark/BookmarksListControls.tsx b/src/components/bookmark/BookmarksListControls.tsx index 85aaf67..58ae32f 100644 --- a/src/components/bookmark/BookmarksListControls.tsx +++ b/src/components/bookmark/BookmarksListControls.tsx @@ -9,6 +9,7 @@ export const BookmarksListControls = ({ linkCount, }: { linkCount: number } & PropsWithChildren) => { const searchParams = useSearchParams(); + const params = new URLSearchParams(searchParams?.toString()); const path = usePathname(); let [isPending, startTransition] = useTransition(); const { replace } = useRouter(); @@ -16,7 +17,6 @@ export const BookmarksListControls = ({ const handleCheckboxChange = () => { if (!searchParams) return; - const params = new URLSearchParams(searchParams); if (params.get('all') === 'true') { params.delete('all'); } else { @@ -28,6 +28,8 @@ export const BookmarksListControls = ({ }); }; + if (params?.get('search') && !linkCount) return null; + return (
{ - if (bookmarks.length < 1) { - return ( - } - title="No bookmark" - subtitle="Start bookmarking links to share them with your team" - /> - ); - } - return (
- -
- {bookmarks.map((bookmark) => ( - - - - ))} -
+ {bookmarks.length < 1 ? ( + } + title="No bookmark" + subtitle="No bookmark matched your search" + /> + ) : ( +
+ {bookmarks.map((bookmark) => ( + + + + ))} +
+ )}
); }; diff --git a/src/components/digests/SearchInput.tsx b/src/components/digests/SearchInput.tsx index f856a91..90dea4c 100644 --- a/src/components/digests/SearchInput.tsx +++ b/src/components/digests/SearchInput.tsx @@ -18,7 +18,7 @@ const SearchInput = ({ /* eslint-disable react-hooks/exhaustive-deps */ const onSearch = useCallback( debounce((e: React.ChangeEvent) => { - const params = new URLSearchParams(searchParams); + const params = new URLSearchParams(searchParams.toString()); params.set('search', e.target.value); startTransition(() => { diff --git a/src/components/list/Pagination.tsx b/src/components/list/Pagination.tsx index 55b1940..b7729bb 100644 --- a/src/components/list/Pagination.tsx +++ b/src/components/list/Pagination.tsx @@ -28,7 +28,7 @@ const Pagination = ({ totalItems < itemsPerPage ? 1 : Math.ceil(totalItems / itemsPerPage); const handlePageChange = (page: number) => { - const params = new URLSearchParams(searchParams); + const params = new URLSearchParams(searchParams.toString()); params.set('page', page.toString()); startTransition(() => { diff --git a/src/components/pages/DigestEditPage.tsx b/src/components/pages/DigestEditPage.tsx index 9a44b4d..56aefd6 100644 --- a/src/components/pages/DigestEditPage.tsx +++ b/src/components/pages/DigestEditPage.tsx @@ -286,6 +286,7 @@ export const DigestEditPage = ({ } title="No bookmark" + subtitle="No bookmark matched your search" /> )}
diff --git a/src/components/pages/Team.tsx b/src/components/pages/Team.tsx index a4e590f..a952111 100644 --- a/src/components/pages/Team.tsx +++ b/src/components/pages/Team.tsx @@ -14,15 +14,18 @@ import { Digests } from '../digests/Digests'; import PageContainer from '../layout/PageContainer'; import { Tooltip } from '../Tooltip'; import { BookmarksListControls } from '../bookmark/BookmarksListControls'; +import NoContent from '../layout/NoContent'; +import { BsFillBookmarkFill } from '@react-icons/all-files/bs/BsFillBookmarkFill'; type Props = { linkCount: number; bookmarks: TeamBookmarksResult[]; digests: TeamDigestsResult[]; team: Awaited>; + search?: string; }; -const Team = ({ team, linkCount, bookmarks, digests }: Props) => { +const Team = ({ team, linkCount, bookmarks, digests, search }: Props) => { return (
@@ -43,11 +46,19 @@ const Team = ({ team, linkCount, bookmarks, digests }: Props) => {
} > - + {!search && !bookmarks?.length ? ( + } + title="No bookmark" + subtitle="Start bookmarking links to share them with your team" + /> + ) : ( + + )}