Skip to content

Commit

Permalink
Trending bookmarks listing (#20)
Browse files Browse the repository at this point in the history
* Trending bookmarks listing

* Fix newsletter bookmark

* Fix type on search

* Naming and delete popover style

* Fix draggable id
  • Loading branch information
Lucieo authored Sep 19, 2023
1 parent c1163fb commit eedb0ba
Show file tree
Hide file tree
Showing 20 changed files with 321 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TeamProvider } from '@/contexts/TeamContext';
import {
checkUserTeamBySlug,
getDigest,
getTeamBookmarksNotInDigest,
getTeamLinks,
updateDefaultTeam,
} from '@/lib/queries';
import { getCurrentUserOrRedirect } from '@/lib/sessions';
Expand Down Expand Up @@ -32,17 +32,16 @@ const page = async ({ params, searchParams }: TeamPageProps) => {

const page = Number(searchParams?.page || 1);
const search = searchParams?.search || '';
const dataBookmarks = await getTeamBookmarksNotInDigest(
team.id,
const teamLinksData = await getTeamLinks(team.id, {
page,
10,
search
);
onlyNotInDigest: true,
search,
});

return (
<TeamProvider team={team}>
<DigestEditPage
dataBookmarks={dataBookmarks}
teamLinksData={teamLinksData}
digest={digest}
team={team}
/>
Expand Down
6 changes: 3 additions & 3 deletions src/app/(routes)/teams/[teamSlug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Team from '@/components/pages/Team';
import db from '@/lib/db';
import {
checkUserTeamBySlug,
getTeamBookmarks,
getTeamLinks,
getTeamDigests,
updateDefaultTeam,
} from '@/lib/queries';
Expand Down Expand Up @@ -39,7 +39,7 @@ const TeamPage = async ({ params, searchParams }: TeamPageProps) => {

const page = Number(searchParams?.page || 1);
const search = searchParams?.search || '';
const { totalCount, bookmarks } = await getTeamBookmarks(team.id, {
const { totalCount, teamLinks } = await getTeamLinks(team.id, {
page,
onlyNotInDigest: !searchParams?.all,
search,
Expand All @@ -51,7 +51,7 @@ const TeamPage = async ({ params, searchParams }: TeamPageProps) => {
<Team
team={team}
linkCount={totalCount}
bookmarks={bookmarks}
teamLinks={teamLinks}
digests={digests}
search={search}
/>
Expand Down
1 change: 0 additions & 1 deletion src/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { Toaster } from 'react-hot-toast';
import { SessionProvider } from 'next-auth/react';
import { QueryClient, QueryClientProvider } from 'react-query';
import messages from '../messages/en.json';

const locale = 'en';

Expand Down
6 changes: 3 additions & 3 deletions src/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps<any>>(
);

export const Switch = forwardRef<HTMLInputElement, HTMLProps<HTMLInputElement>>(
function Switch({ label, onClick, checked, ...props }, ref) {
function Switch({ label, onChange, checked, ...props }, ref) {
const [isChecked, setIsChecked] = useState(checked);
return (
<label className="relative inline-flex cursor-pointer">
Expand All @@ -72,9 +72,9 @@ export const Switch = forwardRef<HTMLInputElement, HTMLProps<HTMLInputElement>>(
type="checkbox"
checked={isChecked}
className="sr-only peer"
onClick={(e) => {
onChange={(e) => {
setIsChecked(!isChecked);
onClick && onClick(e);
onChange && onChange(e);
}}
ref={ref}
{...props}
Expand Down
54 changes: 53 additions & 1 deletion src/components/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
} from '@radix-ui/react-popover';
import { ReactElement, cloneElement, forwardRef } from 'react';
import Button from './Button';
import { TeamBookmarkedLinkItem } from '@/lib/queries';
import { getContributor } from './bookmark/BookmarkItem';
import { TrashIcon } from '@heroicons/react/24/solid';

interface DeletePopoverProps {
trigger?: ReactElement;
Expand All @@ -29,7 +32,7 @@ export const Popover = forwardRef<HTMLButtonElement, PopoverProps & IProps>(
</Trigger>
<Portal>
<Content>
<div className="text-sm flex mt-3 items-center justify-between space-x-8 border rounded-md bg-white p-2 text-gray-700 shadow-lg">
<div className="text-sm flex mt-3 items-center justify-between space-x-8 border rounded-md bg-white p-2 text-gray-700 shadow-lg z-50">
{children}
</div>
</Content>
Expand Down Expand Up @@ -75,3 +78,52 @@ export const DeletePopover = forwardRef<HTMLButtonElement, DeletePopoverProps>(
);

DeletePopover.displayName = 'DeletePopover';

export const MultipleDeletePopover = forwardRef<
HTMLButtonElement,
{
onDelete: (bookmarkId: string) => void;
bookmarks: TeamBookmarkedLinkItem['bookmark'];
trigger?: ReactElement;
isLoading: boolean;
}
>(function MultipleDeletePopover(props, ref) {
const { bookmarks, onDelete, isLoading } = props;

return (
<Popover
trigger={
props.trigger || (
<span
ref={ref}
className="text-xs font-semibold hover:underline cursor-pointer"
>
Delete
</span>
)
}
>
<div className="flex-col z-20">
{bookmarks.map((bookmark) => (
<div className="flex items-center justify-between" key={bookmark?.id}>
<div className="pr-4">{getContributor(bookmark)}</div>
<DeletePopover
handleDelete={() => onDelete(bookmark?.id)}
isLoading={isLoading}
trigger={
<Button
aria-label="Delete digest"
icon={<TrashIcon />}
variant="destructiveGhost"
isLoading={isLoading}
/>
}
/>
</div>
))}
</div>
</Popover>
);
});

MultipleDeletePopover.displayName = 'MultipleDeletePopover';
2 changes: 1 addition & 1 deletion src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const Tooltip = ({
<Content
side="bottom"
sideOffset={5}
className="shadow-md bg-gray-600 text-xs text-white rounded-md p-2"
className="shadow-md bg-gray-600 text-xs text-white rounded-md p-2 z-20"
>
{children}
<Arrow className="fill-gray-600" />
Expand Down
15 changes: 4 additions & 11 deletions src/components/bookmark/BookmarkAddButton.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import useAddAndRemoveBlockOnDigest from '@/hooks/useAddAndRemoveBlockOnDigest';
import { getTeamBookmarksNotInDigest } from '@/lib/queries';
import Link from 'next/link';
import { TeamBookmarkedLinkItem } from '@/lib/queries';
import React from 'react';
import BookmarkImage from '../bookmark/BookmarkImage';
import { AiOutlineLoading3Quarters as LoadingIcon } from '@react-icons/all-files/ai/AiOutlineLoading3Quarters';
import { PlusCircleIcon } from '@heroicons/react/24/solid';
import { getRelativeDate } from '@/utils/date';
import { getDomainFromUrl } from '@/utils/url';
import { BookmarkDigestStyle, DigestBlockType } from '@prisma/client';
import { getEnvHost } from '@/lib/server';
import { isTwitterLink } from '@/utils/link';

interface Props {
bookmark: Awaited<
ReturnType<typeof getTeamBookmarksNotInDigest>
>['bookmarks'][0];
bookmark: TeamBookmarkedLinkItem;
teamId: string;
digestId: string;
}
Expand All @@ -39,9 +32,9 @@ export default function BookmarkAddButton({
onClick={(e) => {
e.preventDefault();
add.mutate({
bookmarkId: bookmark.id,
bookmarkId: bookmark.bookmark[0].id,
type: DigestBlockType.BOOKMARK,
style: isTwitterLink(bookmark.link.url)
style: isTwitterLink(bookmark.url)
? BookmarkDigestStyle.TWEET_EMBED
: BookmarkDigestStyle.BLOCK,
});
Expand Down
Loading

1 comment on commit eedb0ba

@vercel
Copy link

@vercel vercel bot commented on eedb0ba Sep 19, 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.vercel.app
digestclub-git-main-premieroctet.vercel.app
digestclub-premieroctet.vercel.app

Please sign in to comment.