Skip to content

Commit

Permalink
feature(web): Add the ability to view the bookmarks of a particular r…
Browse files Browse the repository at this point in the history
…ss feed
  • Loading branch information
MohamedBassem committed Nov 3, 2024
1 parent cf1a251 commit fa8286a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
31 changes: 31 additions & 0 deletions apps/web/app/dashboard/feeds/[feedId]/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Bookmarks
query={{ rssFeedId: feed.id }}
showDivider={true}
showEditorCard={false}
header={<div className="text-2xl">{feed.name}</div>}
/>
);
}
13 changes: 11 additions & 2 deletions apps/web/components/settings/FeedSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import React from "react";
import Link from "next/link";
import { ActionButton } from "@/components/ui/action-button";
import {
Form,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -302,7 +304,14 @@ export function FeedRow({ feed }: { feed: ZFeed }) {

return (
<TableRow>
<TableCell>{feed.name}</TableCell>
<TableCell>
<Link
href={`/dashboard/feeds/${feed.id}`}
className={cn(buttonVariants({ variant: "link" }))}
>
{feed.name}
</Link>
</TableCell>
<TableCell>{feed.url}</TableCell>
<TableCell>{feed.lastFetchedAt?.toLocaleString()}</TableCell>
<TableCell>
Expand Down
1 change: 1 addition & 0 deletions packages/shared/types/bookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions packages/trpc/routers/bookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
bookmarksInLists,
bookmarkTags,
bookmarkTexts,
rssFeedImportsTable,
tagsOnBookmarks,
} from "@hoarder/db/schema";
import { deleteAsset } from "@hoarder/shared/assetdb";
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions packages/trpc/routers/feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down

0 comments on commit fa8286a

Please sign in to comment.