feat: add post like

This commit is contained in:
gosangam
2026-06-09 16:34:10 +05:30
parent e36afdd1a5
commit 647a803b96
8 changed files with 441 additions and 266 deletions
+27 -8
View File
@@ -99,7 +99,7 @@ export default function NotificationsPage() {
) : (
<ul className="divide-y divide-border rounded-2xl border border-border overflow-hidden">
{items.map((n) => (
<NotificationRow key={n.id} n={n} />
<NotificationRow key={n.id} n={n} selfHandle={user.handle} />
))}
</ul>
)}
@@ -107,9 +107,15 @@ export default function NotificationsPage() {
);
}
function NotificationRow({ n }: { n: AppNotification }) {
function NotificationRow({
n,
selfHandle,
}: {
n: AppNotification;
selfHandle: string;
}) {
const display = n.actor_name || (n.actor_handle ? `@${n.actor_handle}` : "Someone");
const message = messageFor(n.kind);
const message = messageFor(n);
const unread = !n.read_at;
const body = (
@@ -131,10 +137,18 @@ function NotificationRow({ n }: { n: AppNotification }) {
</div>
);
// Link to the actor's profile when we know their handle.
return n.actor_handle ? (
// A like links to your own post; everything else links to the actor's
// profile (when we know their handle).
const href =
n.kind === "post_like" && n.post_id
? `/u/${selfHandle}/posts#post-${n.post_id}`
: n.actor_handle
? `/u/${n.actor_handle}`
: null;
return href ? (
<li>
<Link href={`/u/${n.actor_handle}`} className="block">
<Link href={href} className="block">
{body}
</Link>
</li>
@@ -152,12 +166,17 @@ function cnRow(unread: boolean) {
/** Human-readable tail for each notification kind. Add cases as new
* notification kinds are introduced on the backend. */
function messageFor(kind: string): string {
switch (kind) {
function messageFor(n: AppNotification): string {
switch (n.kind) {
case "follow_request":
return "requested to follow you.";
case "follow_accepted":
return "accepted your follow request.";
case "post_like": {
const others = (n.actor_count ?? 1) - 1;
if (others <= 0) return "liked your post.";
return `and ${others} ${others === 1 ? "other" : "others"} liked your post.`;
}
default:
return "sent you a notification.";
}