11import type { Notification } from "@opencircle/core" ;
22import { Avatar , Button } from "@opencircle/ui" ;
3- import { useNavigate } from "@tanstack/react-router" ;
3+ import { Link , useNavigate } from "@tanstack/react-router" ;
44import moment from "moment" ;
55import { renderContent } from "../../posts/utils/contentRendering" ;
66import { useMarkNotificationAsRead } from "../hooks/useNotifications" ;
@@ -27,16 +27,16 @@ export const NotificationItem = ({ notification }: NotificationItemProps) => {
2727 }
2828 } ;
2929
30- const getNotificationMessage = ( ) => {
30+ const getNotificationAction = ( ) => {
3131 switch ( notification . type ) {
3232 case "mention" :
33- return ` ${ notification . sender . username } mentioned you` ;
33+ return " mentioned you" ;
3434 case "like" :
35- return ` ${ notification . sender . username } liked your post` ;
35+ return " liked your post" ;
3636 case "reply" :
37- return ` ${ notification . sender . username } replied to your post` ;
37+ return " replied to your post" ;
3838 default :
39- return ` ${ notification . sender . username } sent you a notification` ;
39+ return " sent you a notification" ;
4040 }
4141 } ;
4242
@@ -54,44 +54,51 @@ export const NotificationItem = ({ notification }: NotificationItemProps) => {
5454 const isContentNotification = [ "mention" , "reply" ] . includes (
5555 notification . type ,
5656 ) ;
57- const hasPostId = Boolean ( notification . data ?. post_id ) ;
5857
5958 return (
60- < main >
61- < div
62- className = "flex gap-3 p-3 transition-colors duration-150 hover:bg-accent"
63- style = { { opacity : notification . is_read ? "50%" : "100%" } }
64- >
65- < Avatar
66- image_url = { notification . sender . avatar_url || "" }
67- initials = { notification . sender . username . charAt ( 0 ) . toUpperCase ( ) }
68- />
59+ < main
60+ className = "cursor-pointer transition-colors duration-150 hover:bg-accent"
61+ style = { { opacity : notification . is_read ? "50%" : "100%" } }
62+ onClick = { handleViewPost }
63+ >
64+ < div className = "flex gap-3 p-3" >
65+ < Link
66+ to = "/$username"
67+ params = { { username : notification . sender . username } }
68+ onClick = { ( e ) => e . stopPropagation ( ) }
69+ >
70+ < Avatar
71+ image_url = { notification . sender . avatar_url || "" }
72+ initials = { notification . sender . username . charAt ( 0 ) . toUpperCase ( ) }
73+ />
74+ </ Link >
6975 < div className = "min-w-0 flex-1 space-y-1" >
7076 < p className = "truncate text-foreground text-sm" >
71- { getNotificationMessage ( ) }
77+ < Link
78+ to = "/$username"
79+ params = { { username : notification . sender . username } }
80+ className = "font-medium hover:underline"
81+ onClick = { ( e ) => e . stopPropagation ( ) }
82+ >
83+ { notification . sender . username }
84+ </ Link > { " " }
85+ { getNotificationAction ( ) }
7286 </ p >
7387
7488 < p className = "text-muted-foreground text-xs" >
7589 { getTimeAgo ( notification . created_at ) }
7690 </ p >
7791 </ div >
7892 < div className = "flex items-start gap-2" >
79- { hasPostId && (
80- < Button
81- variant = "secondary"
82- size = "sm"
83- onClick = { handleViewPost }
84- className = "text-xs"
85- >
86- View
87- </ Button >
88- ) }
8993 { ! notification . is_read && (
9094 < >
9195 < Button
9296 variant = "secondary"
9397 size = "sm"
94- onClick = { handleMarkAsRead }
98+ onClick = { ( e ) => {
99+ e . stopPropagation ( ) ;
100+ handleMarkAsRead ( ) ;
101+ } }
95102 disabled = { isMarkingAsRead }
96103 className = "text-xs"
97104 >
0 commit comments