Skip to content

Commit c753f03

Browse files
committed
refactor(web/notifications): consume markAllReadForUser from lib core
The notifications page's auto-mark-on-view logic was duplicating the update SQL that the new lib/notifications core already encapsulates. Web and API now share one path: - GET /api/v1/notifications + POST .../mark-read (bots) - notifications page on view (humans) Behavior unchanged. The page still snapshots readAt before the mark so unread items render with their unread style on this render. Removed the inline `sql` template; left `desc` and `eq` in the drizzle import — they're still used by the SELECT for presentation.
1 parent 3a74cf3 commit c753f03

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

  • web/src/app/(reader)/notifications

web/src/app/(reader)/notifications/page.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { ReactNode } from "react";
22
import Link from "next/link";
3-
import { desc, eq, sql } from "drizzle-orm";
3+
import { desc, eq } from "drizzle-orm";
44
import { AtSign, Check, CornerDownRight } from "lucide-react";
55

66
import { db } from "@/db/client";
77
import { notifications, users } from "@/db/schema";
88
import { auth } from "@/lib/auth";
99
import { relativeTime } from "@/lib/format";
1010
import { getCurrentUser } from "@/lib/auth-shim";
11+
import { markAllReadForUser } from "@/lib/notifications";
1112
import { AccountSidebar } from "@/components/prototype/AccountSidebar";
1213

1314
function KindLabel({
@@ -97,12 +98,11 @@ export default async function Notifications({
9798
.orderBy(desc(notifications.createdAt))
9899
.limit(50);
99100

100-
// Mark unread as read on view (fire-and-forget; UI shows the unread state
101-
// already at this point).
102-
await db
103-
.update(notifications)
104-
.set({ readAt: new Date() })
105-
.where(sql`${notifications.userId} = ${userId} AND ${notifications.readAt} IS NULL`);
101+
// Mark unread as read on view. The UI snapshotted readAt above so
102+
// unread items still render with the unread style on this render.
103+
// Shares lib/notifications.markAllReadForUser with the API surface
104+
// so both consume notifications the same way.
105+
await markAllReadForUser(userId);
106106

107107
return (
108108
<div className="proto-page-aside">

0 commit comments

Comments
 (0)