tahamajs's picture
download
raw
2.51 kB
// components/notifications/MessageToast.tsx
"use client";
import { useToast } from "@/context/ToastContext";
import { useNavigate } from "react-router-dom";
export function MessageToast() {
const { toasts, removeToast } = useToast();
const navigate = useNavigate();
if (toasts.length === 0) return null;
return (
<div className="fixed top-4 right-4 z-[100] flex flex-col gap-2 max-w-sm w-full pointer-events-none">
{toasts.map((toast) => (
<div
key={toast.id}
onClick={() => {
removeToast(toast.id);
// Navigate based on type
if (toast.type === "message" || toast.type === "group_message") {
navigate("/messages");
} else if (toast.type === "follow" && toast.payload?.chatUsername) {
navigate(`/users/${toast.payload.chatUsername}`);
} else if (toast.type === "like" || toast.type === "comment") {
if (toast.payload?.articleId) {
navigate(`/articles/${toast.payload.articleId}`);
}
}
}}
className="pointer-events-auto bg-white/95 dark:bg-gray-800/95 backdrop-blur-sm border border-gray-200 dark:border-gray-700 rounded-xl p-4 shadow-lg cursor-pointer animate-slideInRight hover:bg-gray-50 dark:hover:bg-gray-700/80 transition"
>
<div className="flex items-start gap-3">
<div className="w-8 h-8 rounded-full bg-linear-to-br from-primary to-secondary text-white flex items-center justify-center font-bold shrink-0">
{toast.type === "message" || toast.type === "group_message"
? "💬"
: "🔔"}
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium text-gray-900 dark:text-gray-100 truncate">
{toast.message}
</p>
<p className="text-xs text-gray-500 dark:text-gray-400 mt-0.5">
{new Date(toast.createdAt).toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
})}
</p>
</div>
<button
onClick={(e) => {
e.stopPropagation();
removeToast(toast.id);
}}
className="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300"
>
✕
</button>
</div>
</div>
))}
</div>
);
}

Xet Storage Details

Size:
2.51 kB
·
Xet hash:
3a95e934ba44ee06b8d8fe7e259113f668255b6b310a100049f0e2587243b827

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.