feat: add post like
This commit is contained in:
@@ -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.";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user