feat(notification): add unread sidebar count badge and fix project scope upload authorization check

This commit is contained in:
yiling
2026-05-29 23:30:15 +08:00
parent 9c1d672c1e
commit 3ba107bfa4
9 changed files with 147 additions and 27 deletions
+3 -1
View File
@@ -7,6 +7,7 @@ import { UserMenu } from './user-menu'
interface DualSidebarItemProps {
icon: React.ReactNode
label: string
badge?: React.ReactNode
children?: React.ReactNode
onItemClick?: () => void
}
@@ -113,13 +114,14 @@ export const DualSidebar: React.FC<DualSidebarProps> = ({ children }) => {
onClick={() => handleItemClick(index)}
aria-label={item.props.label}
aria-expanded={activeItem === index}
className={`w-12 h-12 [&_svg:not([class*='size-'])]:size-6 transition-all duration-200 ${
className={`relative w-12 h-12 [&_svg:not([class*='size-'])]:size-6 transition-all duration-200 ${
activeItem === index
? 'bg-blue-600 text-white shadow-lg hover:bg-blue-600 hover:text-white'
: 'text-slate-400 hover:text-slate-500 dark:hover:text-slate-400 dark:text-slate-500 hover:bg-slate-200 dark:hover:bg-slate-800'
}`}
>
{item.props.icon}
{item.props.badge}
</Button>
</TooltipTrigger>
<TooltipContent
+8
View File
@@ -55,6 +55,14 @@ export const NotificationList = () => {
[data],
)
useEffect(() => {
if (teamId) {
queryClient.invalidateQueries({
queryKey: ['teams', teamId, 'me'],
})
}
}, [teamId, notifications.length, queryClient])
const $post = client.api.teams[':teamId'].notifications.read.$post
const markReadMutation = useMutation<
InferResponseType<typeof $post>,
+25 -1
View File
@@ -13,6 +13,8 @@ import {
useNavigate,
useRouterState,
} from '@tanstack/react-router'
import { useQuery } from '@tanstack/react-query'
import { client } from '@/ui/api/client'
import { useEffect } from 'react'
function RootComponent() {
@@ -45,6 +47,28 @@ function RootComponent() {
}
}, [teamId, projectId, setTeamId, ensureTeamIdForProject])
const { data: me } = useQuery({
queryKey: ['teams', storedTeamId, 'me'],
queryFn: async () => {
if (!storedTeamId) return null
const res = await client.api.teams[':teamId'].me.$get({
param: { teamId: storedTeamId },
})
if (!res.ok) throw new Error('Failed to fetch me')
return await res.json()
},
enabled: !!storedTeamId,
})
const unreadCount = me?.unreadNotificationCount ?? 0
const displayCount = unreadCount > 99 ? '99+' : unreadCount
const badge =
unreadCount > 0 ? (
<div className="absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 bg-red-500 text-white rounded-full flex items-center justify-center text-[10px] font-bold border-2 border-slate-100 dark:border-slate-900 animate-pulse">
{displayCount}
</div>
) : null
return (
<div className="flex h-screen w-full bg-background overflow-hidden">
<Toaster />
@@ -61,7 +85,7 @@ function RootComponent() {
}
}}
/>
<DualSidebarItem icon={<NotificationFillIcon />} label="Notifications">
<DualSidebarItem icon={<NotificationFillIcon />} label="Notifications" badge={badge}>
<NotificationList />
</DualSidebarItem>
<DualSidebarItem