| import { useNavigate } from "react-router-dom"; | |
| import type { Notification } from "@/types"; | |
| import { MessageSquare, UserPlus, Heart, MessageCircle, AlertCircle, Calendar, Eye, Trash2, Check } from "lucide-react"; | |
| interface NotificationItemProps { | |
| notification: Notification; | |
| onMarkRead: (id: number) => void; | |
| onDelete: (id: number) => void; | |
| onClick?: () => void; | |
| } | |
| export function NotificationItem({ | |
| notification, | |
| onMarkRead, | |
| onDelete, | |
| onClick, | |
| }: NotificationItemProps) { | |
| const navigate = useNavigate(); | |
| const handleClick = () => { | |
| if (onClick) { | |
| onClick(); | |
| return; | |
| } | |
| onMarkRead(notification.id); | |
| if (notification.type === "message" || notification.type === "group_message") { | |
| navigate("/messages"); | |
| } else if (notification.articleId) { | |
| navigate(`/articles/${notification.articleId}`); | |
| } else if (notification.type === "follow" && notification.fromUser) { | |
| navigate(`/users/${notification.fromUser}`); | |
| } | |
| }; | |
| const getIconAndBg = () => { | |
| switch (notification.type) { | |
| case "message": | |
| return { | |
| icon: <MessageSquare className="w-5 h-5 text-blue-400" />, | |
| bg: "from-blue-500/10 to-indigo-500/10 border-blue-500/20", | |
| badge: "bg-blue-500/20 text-blue-300", | |
| }; | |
| case "group_message": | |
| return { | |
| icon: <MessageCircle className="w-5 h-5 text-indigo-400" />, | |
| bg: "from-indigo-500/10 to-violet-500/10 border-indigo-500/20", | |
| badge: "bg-indigo-500/20 text-indigo-300", | |
| }; | |
| case "follow": | |
| return { | |
| icon: <UserPlus className="w-5 h-5 text-emerald-400" />, | |
| bg: "from-emerald-500/10 to-teal-500/10 border-emerald-500/20", | |
| badge: "bg-emerald-500/20 text-emerald-300", | |
| }; | |
| case "like": | |
| return { | |
| icon: <Heart className="w-5 h-5 text-pink-400 fill-pink-400/20" />, | |
| bg: "from-pink-500/10 to-rose-500/10 border-pink-500/20", | |
| badge: "bg-pink-500/20 text-pink-300", | |
| }; | |
| case "comment": | |
| return { | |
| icon: <MessageSquare className="w-5 h-5 text-purple-400" />, | |
| bg: "from-purple-500/10 to-fuchsia-500/10 border-purple-500/20", | |
| badge: "bg-purple-500/20 text-purple-300", | |
| }; | |
| default: | |
| return { | |
| icon: <AlertCircle className="w-5 h-5 text-amber-400" />, | |
| bg: "from-amber-500/10 to-orange-500/10 border-amber-500/20", | |
| badge: "bg-amber-500/20 text-amber-300", | |
| }; | |
| } | |
| }; | |
| const styleConfig = getIconAndBg(); | |
| return ( | |
| <div | |
| onClick={handleClick} | |
| className={`group relative overflow-hidden rounded-2xl p-5 flex items-start gap-4 transition-all duration-300 cursor-pointer border hover-lift ${ | |
| !notification.read | |
| ? "border-teal-500/30 bg-slate-900/60 shadow-[0_0_15px_rgba(20,184,166,0.05)]" | |
| : "border-white/5 bg-slate-950/40 hover:bg-slate-900/40" | |
| }`} | |
| > | |
| {/* Read status border line */} | |
| {!notification.read && ( | |
| <div className="absolute left-0 top-0 bottom-0 w-1 bg-gradient-to-b from-teal-400 to-blue-500" /> | |
| )} | |
| {/* Icon Area */} | |
| <div className={`p-3 rounded-xl bg-gradient-to-br ${styleConfig.bg} border flex items-center justify-center shrink-0 shadow-inner group-hover:scale-110 transition-transform duration-300`}> | |
| {styleConfig.icon} | |
| </div> | |
| {/* Content Area */} | |
| <div className="flex-1 min-w-0 space-y-1"> | |
| <div className="flex items-center gap-2"> | |
| <span className={`text-[10px] font-bold tracking-wider uppercase px-2 py-0.5 rounded-md ${styleConfig.badge}`}> | |
| {notification.type.replace("_", " ")} | |
| </span> | |
| {!notification.read && ( | |
| <span className="flex h-2 w-2 rounded-full bg-teal-400 animate-pulse" /> | |
| )} | |
| </div> | |
| <p className={`text-sm leading-relaxed transition-colors duration-200 ${ | |
| !notification.read ? "text-slate-100 font-medium" : "text-slate-300" | |
| }`}> | |
| {notification.message} | |
| </p> | |
| <div className="flex items-center gap-1 text-slate-500 text-xs"> | |
| <Calendar className="w-3.5 h-3.5" /> | |
| <span>{new Date(notification.createdAt).toLocaleString()}</span> | |
| </div> | |
| </div> | |
| {/* Actions Area */} | |
| <div className="flex gap-2 shrink-0 self-center opacity-0 group-hover:opacity-100 transition-opacity duration-300" onClick={(e) => e.stopPropagation()}> | |
| {!notification.read && ( | |
| <button | |
| onClick={() => onMarkRead(notification.id)} | |
| title="Mark as Read" | |
| className="p-2 rounded-xl bg-teal-500/10 hover:bg-teal-500/20 text-teal-400 border border-teal-500/20 transition-all hover:scale-105 active:scale-95" | |
| > | |
| <Check className="w-4 h-4" /> | |
| </button> | |
| )} | |
| <button | |
| onClick={() => onDelete(notification.id)} | |
| title="Delete Notification" | |
| className="p-2 rounded-xl bg-red-500/10 hover:bg-red-200/20 text-red-400 border border-red-500/20 transition-all hover:scale-105 active:scale-95" | |
| > | |
| <Trash2 className="w-4 h-4" /> | |
| </button> | |
| </div> | |
| </div> | |
| ); | |
| } | |
Xet Storage Details
- Size:
- 5.26 kB
- Xet hash:
- 50ab04a8f37e59a801b9f4520a9369d1914a13fb592081600e7376ce6dd27596
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.