Skip to content

Commit

Permalink
Fix/no results search (#16)
Browse files Browse the repository at this point in the history
* Distinguish no bookmarks and / no search result

* Unify wording

* Hide controls if no search results

* Fix issue with URLSearchParams
  • Loading branch information
Lucieo authored Sep 18, 2023
1 parent 49eedba commit f6f7cdf
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 46 deletions.
1 change: 1 addition & 0 deletions src/app/(routes)/teams/[teamSlug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const TeamPage = async ({ params, searchParams }: TeamPageProps) => {
linkCount={totalCount}
bookmarks={bookmarks}
digests={digests}
search={search}
/>
);
};
Expand Down
4 changes: 3 additions & 1 deletion src/components/bookmark/BookmarksListControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ 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();

const handleCheckboxChange = () => {
if (!searchParams) return;

const params = new URLSearchParams(searchParams);
if (params.get('all') === 'true') {
params.delete('all');
} else {
Expand All @@ -28,6 +28,8 @@ export const BookmarksListControls = ({
});
};

if (params?.get('search') && !linkCount) return null;

return (
<div className="flex items-center justify-end gap-3 max-sm:w-full max-sm:justify-between">
<Switch
Expand Down
63 changes: 26 additions & 37 deletions src/components/bookmark/BookmarksTeamList.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
'use client';

import useCustomToast from '@/hooks/useCustomToast';
import useTransitionRefresh from '@/hooks/useTransitionRefresh';
import api from '@/lib/api';
import { TeamBookmarksResult } from '@/lib/queries';
import { ApiBookmarkResponseSuccess } from '@/pages/api/teams/[teamId]/bookmark';
import { BsFillBookmarkFill } from '@react-icons/all-files/bs/BsFillBookmarkFill';
import { AxiosError, AxiosResponse } from 'axios';
import clsx from 'clsx';
import { useMutation } from 'react-query';
import NoContent from '../layout/NoContent';
import message from '../../messages/en';
import { BookmarkItem } from './BookmarkItem';
import Link from 'next/link';
import SearchInput from '../digests/SearchInput';
Expand All @@ -22,38 +14,35 @@ type Props = {
};

export const BookmarksTeamList = ({ bookmarks, teamId, teamSlug }: Props) => {
if (bookmarks.length < 1) {
return (
<NoContent
icon={<BsFillBookmarkFill />}
title="No bookmark"
subtitle="Start bookmarking links to share them with your team"
/>
);
}

return (
<div className="w-full">
<SearchInput className="mb-4" />

<div className="flex flex-col gap-2">
{bookmarks.map((bookmark) => (
<Link
key={bookmark?.id}
href={bookmark.link.url}
target="_blank"
rel="noopener noreferrer"
>
<BookmarkItem
bookmark={bookmark}
teamSlug={teamSlug}
teamId={teamId}
digestId={bookmark.digestBlocks[0]?.digest.id}
nbOfTimesUsed={bookmark.digestBlocks.length}
/>
</Link>
))}
</div>
{bookmarks.length < 1 ? (
<NoContent
icon={<BsFillBookmarkFill />}
title="No bookmark"
subtitle="No bookmark matched your search"
/>
) : (
<div className="flex flex-col gap-2">
{bookmarks.map((bookmark) => (
<Link
key={bookmark?.id}
href={bookmark.link.url}
target="_blank"
rel="noopener noreferrer"
>
<BookmarkItem
bookmark={bookmark}
teamSlug={teamSlug}
teamId={teamId}
digestId={bookmark.digestBlocks[0]?.digest.id}
nbOfTimesUsed={bookmark.digestBlocks.length}
/>
</Link>
))}
</div>
)}
</div>
);
};
2 changes: 1 addition & 1 deletion src/components/digests/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const SearchInput = ({
/* eslint-disable react-hooks/exhaustive-deps */
const onSearch = useCallback(
debounce((e: React.ChangeEvent<HTMLInputElement>) => {
const params = new URLSearchParams(searchParams);
const params = new URLSearchParams(searchParams.toString());
params.set('search', e.target.value);

startTransition(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/list/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
1 change: 1 addition & 0 deletions src/components/pages/DigestEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export const DigestEditPage = ({
<NoContent
icon={<BsFillBookmarkFill />}
title="No bookmark"
subtitle="No bookmark matched your search"
/>
)}
</div>
Expand Down
23 changes: 17 additions & 6 deletions src/components/pages/Team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof getTeamBySlug>>;
search?: string;
};

const Team = ({ team, linkCount, bookmarks, digests }: Props) => {
const Team = ({ team, linkCount, bookmarks, digests, search }: Props) => {
return (
<PageContainer title={team.name}>
<div className="flex max-lg:flex-col gap-5 pb-4">
Expand All @@ -43,11 +46,19 @@ const Team = ({ team, linkCount, bookmarks, digests }: Props) => {
</div>
}
>
<BookmarksTeamList
teamId={team.id}
teamSlug={team.slug}
bookmarks={bookmarks}
/>
{!search && !bookmarks?.length ? (
<NoContent
icon={<BsFillBookmarkFill />}
title="No bookmark"
subtitle="Start bookmarking links to share them with your team"
/>
) : (
<BookmarksTeamList
teamId={team.id}
teamSlug={team.slug}
bookmarks={bookmarks}
/>
)}
</Card>
<Card
className="w-full lg:w-1/3"
Expand Down

1 comment on commit f6f7cdf

@vercel
Copy link

@vercel vercel bot commented on f6f7cdf Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

digestclub – ./

digestclub-premieroctet.vercel.app
digestclub-git-main-premieroctet.vercel.app
digestclub.vercel.app

Please sign in to comment.