| // @ts-nocheck | |
| // src/components/UnreadMessagesCard.tsx | |
| import { Link } from "react-router-dom"; | |
| import { useAuth } from "@/context/AuthContext"; | |
| import { useState, useEffect } from "react"; | |
| import api from "@/lib/api"; | |
| import { Loader2, MessageCircle } from "lucide-react"; | |
| export function UnreadMessagesCard() { | |
| const { user } = useAuth(); | |
| const [unreadCount, setUnreadCount] = useState<number | null>(null); | |
| const [loading, setLoading] = useState(true); | |
| useEffect(() => { | |
| if (!user) { | |
| setLoading(false); | |
| return; | |
| } | |
| api | |
| .get("/notifications/unread-count?type=message") | |
| .then((res) => setUnreadCount(res.data?.byType?.message ?? res.data.unreadCount ?? res.data.count ?? 0)) | |
| .catch(() => setUnreadCount(0)) | |
| .finally(() => setLoading(false)); | |
| }, [user]); | |
| if (loading) { | |
| return ( | |
| <div className="flex items-center gap-4 rounded-2xl bg-white p-6 shadow-md dark:bg-gray-800"> | |
| <div className="flex h-12 w-12 items-center justify-center rounded-full bg-primary/10"> | |
| <Loader2 className="h-5 w-5 animate-spin text-primary" /> | |
| </div> | |
| <div className="flex-1"> | |
| <h3 className="text-lg font-semibold">Messages</h3> | |
| <p className="text-sm text-gray-500">Loading unread count…</p> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| if (!user || unreadCount === 0) return null; | |
| return ( | |
| <Link | |
| to="/messages" | |
| className="flex items-center gap-4 rounded-2xl bg-white p-6 shadow-md transition hover:shadow-lg dark:bg-gray-800" | |
| > | |
| <div className="flex h-12 w-12 items-center justify-center rounded-full bg-primary/10 text-2xl"> | |
| <MessageCircle className="h-6 w-6 text-primary" /> | |
| </div> | |
| <div className="flex-1"> | |
| <h3 className="text-lg font-semibold">Messages</h3> | |
| <p className="text-sm text-gray-500"> | |
| {unreadCount} unread message{unreadCount > 1 ? "s" : ""} | |
| </p> | |
| </div> | |
| <span className="rounded-full bg-primary px-2 py-1 text-xs font-bold text-white"> | |
| {unreadCount} | |
| </span> | |
| </Link> | |
| ); | |
| } | |
Xet Storage Details
- Size:
- 2.1 kB
- Xet hash:
- 8ef910ad642c19332d5be155af6052e33ec1fba01ec2141f4eeb1b23ca7c6b8c
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.