style: clean up code formatting and remove trailing whitespace
refactor: reorganize imports and fix type imports
This commit is contained in:
1 parent
d3704602fd
commit
47c04de6fe
232 files changed
+7140
-4798
No files matched your search
@@ -1,16 +1,16 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { Bell } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { NotificationDropdown } from "./NotificationDropdown";
|
||||
import { useSession } from "@/lib/hooks/use-session";
|
||||
import { NotificationDropdown } from "./NotificationDropdown";
|
||||
|
||||
interface Notification {
|
||||
notification_id: number;
|
||||
@@ -32,7 +32,7 @@ export function NotificationBell({ userId, className }: NotificationBellProps) {
|
||||
const [unreadCount, setUnreadCount] = useState(0);
|
||||
const [notifications, setNotifications] = useState<Notification[]>([]);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [_loading, setLoading] = useState(false);
|
||||
const rawUnreadRef = useRef(0);
|
||||
const baselineUnreadRef = useRef(0);
|
||||
const baselineLoadedRef = useRef(false);
|
||||
@@ -122,7 +122,7 @@ export function NotificationBell({ userId, className }: NotificationBellProps) {
|
||||
baselineUnreadRef.current = 0;
|
||||
baselineLoadedRef.current = false;
|
||||
}
|
||||
}, [effectiveUserId]);
|
||||
}, [effectiveUserId, loadBaselineFromStorage]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!effectiveUserId) return;
|
||||
@@ -138,7 +138,7 @@ export function NotificationBell({ userId, className }: NotificationBellProps) {
|
||||
}, 30000); // 30 segundos
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [effectiveUserId, isOpen]);
|
||||
}, [effectiveUserId, isOpen, fetchNotifications, fetchUnreadCount]);
|
||||
|
||||
// Atualizar quando abrir popover
|
||||
useEffect(() => {
|
||||
@@ -147,7 +147,7 @@ export function NotificationBell({ userId, className }: NotificationBellProps) {
|
||||
persistBaseline(rawUnreadRef.current);
|
||||
setUnreadCount(0);
|
||||
}
|
||||
}, [isOpen]);
|
||||
}, [isOpen, fetchNotifications, persistBaseline]);
|
||||
|
||||
const handleMarkAsRead = async (notificationId: number) => {
|
||||
try {
|
||||
@@ -159,14 +159,14 @@ export function NotificationBell({ userId, className }: NotificationBellProps) {
|
||||
// Atualizar estado local
|
||||
setNotifications((prev) =>
|
||||
prev.map((n) =>
|
||||
n.notification_id === notificationId ? { ...n, is_read: true } : n
|
||||
)
|
||||
n.notification_id === notificationId ? { ...n, is_read: true } : n,
|
||||
),
|
||||
);
|
||||
// Atualizar contagem
|
||||
rawUnreadRef.current = Math.max(0, rawUnreadRef.current - 1);
|
||||
const newBaseline = Math.min(
|
||||
baselineUnreadRef.current,
|
||||
rawUnreadRef.current
|
||||
rawUnreadRef.current,
|
||||
);
|
||||
persistBaseline(newBaseline);
|
||||
setUnreadCount((prev) => Math.max(0, prev - 1));
|
||||
@@ -209,4 +209,3 @@ export function NotificationBell({ userId, className }: NotificationBellProps) {
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
Bell,
|
||||
ExternalLink,
|
||||
MessageSquare,
|
||||
ShoppingCart,
|
||||
TrendingUp,
|
||||
} from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useLocale } from "next-intl";
|
||||
import { Button } from "@/components/ui/button";
|
||||
// ScrollArea não disponível, usando div com overflow
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { Bell, ShoppingCart, TrendingUp, MessageSquare, ExternalLink } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useLocale } from "next-intl";
|
||||
|
||||
interface Notification {
|
||||
notification_id: number;
|
||||
@@ -24,10 +30,11 @@ interface NotificationDropdownProps {
|
||||
}
|
||||
|
||||
function formatTimeAgo(date: Date): string {
|
||||
const seconds = Math.floor((new Date().getTime() - date.getTime()) / 1000);
|
||||
const seconds = Math.floor((Date.now() - date.getTime()) / 1000);
|
||||
if (seconds < 60) return "há alguns segundos";
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
if (minutes < 60) return `há ${minutes} ${minutes === 1 ? "minuto" : "minutos"}`;
|
||||
if (minutes < 60)
|
||||
return `há ${minutes} ${minutes === 1 ? "minuto" : "minutos"}`;
|
||||
const hours = Math.floor(minutes / 60);
|
||||
if (hours < 24) return `há ${hours} ${hours === 1 ? "hora" : "horas"}`;
|
||||
const days = Math.floor(hours / 24);
|
||||
@@ -118,14 +125,16 @@ export function NotificationDropdown({
|
||||
<div className="flex items-start gap-3">
|
||||
<div
|
||||
className={`${getNotificationColor(
|
||||
notification.notification_type
|
||||
notification.notification_type,
|
||||
)} rounded-full p-2 text-white flex-shrink-0`}
|
||||
>
|
||||
{getNotificationIcon(notification.notification_type)}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<h4 className="font-medium text-sm">{notification.title}</h4>
|
||||
<h4 className="font-medium text-sm">
|
||||
{notification.title}
|
||||
</h4>
|
||||
{!notification.is_read && (
|
||||
<div className="h-2 w-2 bg-primary rounded-full flex-shrink-0 mt-1" />
|
||||
)}
|
||||
@@ -148,7 +157,9 @@ export function NotificationDropdown({
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
{index < notifications.length - 1 && <Separator className="my-2" />}
|
||||
{index < notifications.length - 1 && (
|
||||
<Separator className="my-2" />
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -156,4 +167,3 @@ export function NotificationDropdown({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user