From fa8286aa900ea4f13c1c15d5b0f441436f042d8a Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 3 Nov 2024 17:30:17 +0000 Subject: [PATCH] feature(web): Add the ability to view the bookmarks of a particular rss feed --- .../web/app/dashboard/feeds/[feedId]/page.tsx | 31 +++++++++++++++++++ apps/web/components/settings/FeedSettings.tsx | 13 ++++++-- packages/shared/types/bookmarks.ts | 1 + packages/trpc/routers/bookmarks.ts | 14 +++++++++ packages/trpc/routers/feeds.ts | 20 ++++++++++++ 5 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 apps/web/app/dashboard/feeds/[feedId]/page.tsx diff --git a/apps/web/app/dashboard/feeds/[feedId]/page.tsx b/apps/web/app/dashboard/feeds/[feedId]/page.tsx new file mode 100644 index 00000000..ed5f9e40 --- /dev/null +++ b/apps/web/app/dashboard/feeds/[feedId]/page.tsx @@ -0,0 +1,31 @@ +import { notFound } from "next/navigation"; +import Bookmarks from "@/components/dashboard/bookmarks/Bookmarks"; +import { api } from "@/server/api/client"; +import { TRPCError } from "@trpc/server"; + +export default async function FeedPage({ + params, +}: { + params: { feedId: string }; +}) { + let feed; + try { + feed = await api.feeds.get({ feedId: params.feedId }); + } catch (e) { + if (e instanceof TRPCError) { + if (e.code == "NOT_FOUND") { + notFound(); + } + } + throw e; + } + + return ( + {feed.name}} + /> + ); +} diff --git a/apps/web/components/settings/FeedSettings.tsx b/apps/web/components/settings/FeedSettings.tsx index 9f2dbda9..09e6264c 100644 --- a/apps/web/components/settings/FeedSettings.tsx +++ b/apps/web/components/settings/FeedSettings.tsx @@ -1,6 +1,7 @@ "use client"; import React from "react"; +import Link from "next/link"; import { ActionButton } from "@/components/ui/action-button"; import { Form, @@ -14,6 +15,7 @@ import { FullPageSpinner } from "@/components/ui/full-page-spinner"; import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/use-toast"; import { api } from "@/lib/trpc"; +import { cn } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { ArrowDownToLine, @@ -35,7 +37,7 @@ import { } from "@hoarder/shared/types/feeds"; import ActionConfirmingDialog from "../ui/action-confirming-dialog"; -import { Button } from "../ui/button"; +import { Button, buttonVariants } from "../ui/button"; import { Dialog, DialogClose, @@ -302,7 +304,14 @@ export function FeedRow({ feed }: { feed: ZFeed }) { return ( - {feed.name} + + + {feed.name} + + {feed.url} {feed.lastFetchedAt?.toLocaleString()} diff --git a/packages/shared/types/bookmarks.ts b/packages/shared/types/bookmarks.ts index 2d46684e..1d8052f4 100644 --- a/packages/shared/types/bookmarks.ts +++ b/packages/shared/types/bookmarks.ts @@ -133,6 +133,7 @@ export const zGetBookmarksRequestSchema = z.object({ favourited: z.boolean().optional(), tagId: z.string().optional(), listId: z.string().optional(), + rssFeedId: z.string().optional(), limit: z.number().max(MAX_NUM_BOOKMARKS_PER_PAGE).optional(), cursor: zCursorV2.nullish(), // TODO: This was done for backward comptability. At this point, all clients should be settings this to true. diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index 9a27c25a..4e58bcdc 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -18,6 +18,7 @@ import { bookmarksInLists, bookmarkTags, bookmarkTexts, + rssFeedImportsTable, tagsOnBookmarks, } from "@hoarder/db/schema"; import { deleteAsset } from "@hoarder/shared/assetdb"; @@ -591,6 +592,19 @@ export const bookmarksAppRouter = router({ ), ) : undefined, + input.rssFeedId !== undefined + ? exists( + ctx.db + .select() + .from(rssFeedImportsTable) + .where( + and( + eq(rssFeedImportsTable.bookmarkId, bookmarks.id), + eq(rssFeedImportsTable.rssFeedId, input.rssFeedId), + ), + ), + ) + : undefined, input.listId !== undefined ? exists( ctx.db diff --git a/packages/trpc/routers/feeds.ts b/packages/trpc/routers/feeds.ts index a8025dfb..e5520474 100644 --- a/packages/trpc/routers/feeds.ts +++ b/packages/trpc/routers/feeds.ts @@ -82,6 +82,26 @@ export const feedsAppRouter = router({ } return feed[0]; }), + get: authedProcedure + .input( + z.object({ + feedId: z.string(), + }), + ) + .output(zFeedSchema) + .use(ensureFeedOwnership) + .query(async ({ ctx, input }) => { + const feed = await ctx.db.query.rssFeedsTable.findFirst({ + where: and( + eq(rssFeedsTable.userId, ctx.user.id), + eq(rssFeedsTable.id, input.feedId), + ), + }); + if (!feed) { + throw new TRPCError({ code: "NOT_FOUND" }); + } + return feed; + }), list: authedProcedure .output(z.object({ feeds: z.array(zFeedSchema) })) .query(async ({ ctx }) => {