import { useState, useEffect } from 'react' import { Link, useLocation } from 'react-router-dom' import api from '@/services/api' import type { User } from '@/types' interface Props { user: User | null onLogout: () => void } export default function Sidebar({ user, onLogout }: Props) { const { pathname } = useLocation() const [unreadCount, setUnreadCount] = useState(0) useEffect(() => { if (!user) { setUnreadCount(0) return } api.get<{ count: number }>('/notifications/count') .then(({ data }) => setUnreadCount(data.count)) .catch(() => {}) const timer = setInterval(() => { api.get<{ count: number }>('/notifications/count') .then(({ data }) => setUnreadCount(data.count)) .catch(() => {}) }, 30000) return () => clearInterval(timer) }, [user]) const links = user ? [ { to: '/', icon: '๐Ÿ“Š', label: 'ไปช่กจ็›˜' }, { to: '/issues', icon: '๐Ÿ“‹', label: 'Issues' }, { to: '/projects', icon: '๐Ÿ“', label: '้กน็›ฎ' }, { to: '/milestones', icon: '๐Ÿ', label: '้‡Œ็จ‹็ข‘' }, { to: '/notifications', icon: '๐Ÿ””', label: '้€š็Ÿฅ' + (unreadCount > 0 ? ' (' + unreadCount + ')' : '') }, { to: '/monitor', icon: '๐Ÿ“ก', label: 'Monitor' }, ] : [ { to: '/monitor', icon: '๐Ÿ“ก', label: 'Monitor' }, ] return ( ) }