diff --git a/client/components/app/Navbar/Collapsed.jsx b/client/components/app/Navbar/Collapsed.jsx index b6bd2a6..5061bf8 100644 --- a/client/components/app/Navbar/Collapsed.jsx +++ b/client/components/app/Navbar/Collapsed.jsx @@ -5,6 +5,7 @@ import { Home, Compass, Bell, Menu, User, Settings } from 'lucide-react'; import Item from '@/components/app/Navbar/Item'; import Dropdown from '@/components/app/Navbar/Dropdown'; import PostModal from '@/components/app/Navbar/PostModal'; +import NotificationButton from '@/components/app/Navbar/Notification'; import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet'; import { Button } from '@/components/ui/button'; import { useAuthStore } from '@/stores/auth'; @@ -65,12 +66,7 @@ export default function Collapsed({ router, pathname }) { icon={Compass} label='keşfet' /> - +
yaratıcılık diff --git a/client/components/app/Navbar/Item.jsx b/client/components/app/Navbar/Item.jsx index d9c4ba6..9eeddf6 100644 --- a/client/components/app/Navbar/Item.jsx +++ b/client/components/app/Navbar/Item.jsx @@ -1,46 +1,19 @@ import Link from 'next/link'; -import { useState, useEffect } from 'react'; -import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; -import { getUnreadNotificationsCount } from '@/lib/api/me'; export default function Item({ pathname, href, icon: Icon, label }) { const isActive = pathname === href || (href !== '/app' && pathname.startsWith(href)); - const [unreadNotificationsCount, setUnreadNotificationsCount] = useState(0); - - useEffect( - () => { - const fetchUnreadNotificationsCount = async () => { - const response = await getUnreadNotificationsCount(); - if (response) { - setUnreadNotificationsCount(response.data.unreads); - } - }; - - fetchUnreadNotificationsCount(); - }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [] - ); - return ( ); diff --git a/client/components/app/Navbar/Notification.jsx b/client/components/app/Navbar/Notification.jsx new file mode 100644 index 0000000..ce44143 --- /dev/null +++ b/client/components/app/Navbar/Notification.jsx @@ -0,0 +1,47 @@ +import Link from 'next/link'; +import { useEffect } from 'react'; +import { Bell } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Badge } from '@/components/ui/badge'; +import { getUnreadNotificationsCount } from '@/lib/api/me'; +import { useNotificationStore } from '@/stores/notification'; + +export default function NotificationButton({ pathname }) { + const isActive = pathname === '/app/notifications'; + + const notificationCount = useNotificationStore( + (state) => state.notificationCount + ); + const setNotificationCount = useNotificationStore( + (state) => state.setNotificationCount + ); + + useEffect(() => { + const fetchUnreadNotificationsCount = async () => { + const response = await getUnreadNotificationsCount(); + if (!response) return; + + setNotificationCount(response.data.unreads); + }; + + fetchUnreadNotificationsCount(); + }, [setNotificationCount]); + + return ( + + ); +} diff --git a/client/components/app/Navbar/Uncollapsed.jsx b/client/components/app/Navbar/Uncollapsed.jsx index 9dbfaed..0290568 100644 --- a/client/components/app/Navbar/Uncollapsed.jsx +++ b/client/components/app/Navbar/Uncollapsed.jsx @@ -1,9 +1,10 @@ import Link from 'next/link'; import Image from 'next/image'; -import { Home, Compass, Bell } from 'lucide-react'; +import { Home, Compass } from 'lucide-react'; import Item from '@/components/app/Navbar/Item'; import Dropdown from '@/components/app/Navbar/Dropdown'; import PostModal from '@/components/app/Navbar/PostModal'; +import NotificationButton from '@/components/app/Navbar/Notification'; export default function Uncollapsed({ router, pathname }) { return ( @@ -34,12 +35,7 @@ export default function Uncollapsed({ router, pathname }) { icon={Compass} label='keşfet' /> - +
yaratıcılık diff --git a/client/components/app/Notification/Skeleton.jsx b/client/components/app/Notification/Skeleton.jsx index b71b13c..7416996 100644 --- a/client/components/app/Notification/Skeleton.jsx +++ b/client/components/app/Notification/Skeleton.jsx @@ -12,5 +12,5 @@ export default function NotificationSkeleton() {
- ) -} \ No newline at end of file + ); +} diff --git a/client/components/app/Notification/index.jsx b/client/components/app/Notification/index.jsx index c9d759d..91f4eb2 100644 --- a/client/components/app/Notification/index.jsx +++ b/client/components/app/Notification/index.jsx @@ -5,6 +5,7 @@ import UserInfo from '@/components/app/User/Info'; import { Button } from '@/components/ui/button'; import { useToast } from '@/components/ui/use-toast'; import { updateNotification } from '@/lib/api/me'; +import { useNotificationStore } from '@/stores/notification'; function typeContent(notification) { switch (notification.type) { @@ -33,6 +34,12 @@ function typeContent(notification) { export default function Notification({ notification }) { const [isRead, setIsRead] = useState(notification.read); + const notificationCount = useNotificationStore( + (state) => state.notificationCount + ); + const setNotificationCount = useNotificationStore( + (state) => state.setNotificationCount + ); const { toast } = useToast(); const markAsRead = async ({ read }) => { @@ -51,6 +58,7 @@ export default function Notification({ notification }) { } setIsRead(!read); + setNotificationCount(!read ? notificationCount - 1 : notificationCount + 1); }; return ( @@ -69,7 +77,12 @@ export default function Notification({ notification }) { )} -