2025-11-28 06:31:36 +00:00
|
|
|
import { Badge } from '@/components/ui/badge'
|
|
|
|
|
import { useCurrentUser, useUserNoticeStat } from '@/hooks/auth'
|
|
|
|
|
import Image from 'next/image'
|
|
|
|
|
import { useState, useEffect } from 'react'
|
|
|
|
|
import { usePathname } from 'next/navigation'
|
|
|
|
|
import { useQueryClient } from '@tanstack/react-query'
|
|
|
|
|
import { userKeys } from '@/lib/query-keys'
|
|
|
|
|
import NoticeDrawer from './NoticeDrawer'
|
2025-11-13 08:38:25 +00:00
|
|
|
|
2025-11-28 06:31:36 +00:00
|
|
|
const Notice = ({ actualIsExpanded }: { actualIsExpanded: boolean }) => {
|
|
|
|
|
const { data: user } = useCurrentUser()
|
|
|
|
|
const [isDrawerOpen, setIsDrawerOpen] = useState(false)
|
|
|
|
|
const pathname = usePathname()
|
|
|
|
|
const queryClient = useQueryClient()
|
|
|
|
|
|
|
|
|
|
const { data } = useUserNoticeStat()
|
2025-11-13 08:38:25 +00:00
|
|
|
|
|
|
|
|
// 监听路径变化,刷新通知统计
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (user) {
|
|
|
|
|
// 当路径变化时,无效化并重新获取通知统计数据
|
|
|
|
|
queryClient.invalidateQueries({
|
2025-11-28 06:31:36 +00:00
|
|
|
queryKey: userKeys.noticeStat(),
|
|
|
|
|
})
|
2025-11-13 08:38:25 +00:00
|
|
|
}
|
2025-11-28 06:31:36 +00:00
|
|
|
}, [pathname])
|
2025-11-13 08:38:25 +00:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (isDrawerOpen && user) {
|
|
|
|
|
queryClient.invalidateQueries({
|
2025-11-28 06:31:36 +00:00
|
|
|
queryKey: userKeys.noticeStat(),
|
|
|
|
|
})
|
2025-11-13 08:38:25 +00:00
|
|
|
}
|
|
|
|
|
}, [isDrawerOpen])
|
2025-11-28 06:31:36 +00:00
|
|
|
|
2025-11-13 08:38:25 +00:00
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
{/* 分割线 */}
|
|
|
|
|
{user && (
|
2025-11-28 06:31:36 +00:00
|
|
|
<div className="mx-6 my-4">
|
|
|
|
|
<div className="bg-outline-normal h-px" />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-11-13 08:38:25 +00:00
|
|
|
|
2025-11-28 06:31:36 +00:00
|
|
|
{/* 底部通知 */}
|
|
|
|
|
{user && (
|
2025-11-13 08:38:25 +00:00
|
|
|
<div className="px-4">
|
2025-11-28 06:31:36 +00:00
|
|
|
<div
|
|
|
|
|
className="hover:bg-surface-element-hover flex cursor-pointer items-center gap-3 rounded-full p-2 transition-colors"
|
2025-11-13 08:38:25 +00:00
|
|
|
onClick={() => setIsDrawerOpen(true)}
|
|
|
|
|
>
|
2025-11-28 06:31:36 +00:00
|
|
|
<div className="relative flex h-8 w-8 flex-shrink-0 items-center justify-center">
|
2025-11-13 08:38:25 +00:00
|
|
|
<Image src="/icons/notice.svg" alt="Notice" width={32} height={32} />
|
|
|
|
|
<Badge count={data?.unRead} className="absolute -top-2 -right-2" />
|
|
|
|
|
</div>
|
|
|
|
|
{actualIsExpanded && (
|
2025-11-28 06:31:36 +00:00
|
|
|
<span className="txt-label-m text-txt-primary-normal flex-1">Notice</span>
|
2025-11-13 08:38:25 +00:00
|
|
|
)}
|
|
|
|
|
</div>
|
2025-11-28 06:31:36 +00:00
|
|
|
</div>
|
|
|
|
|
)}
|
2025-11-13 08:38:25 +00:00
|
|
|
|
2025-11-28 06:31:36 +00:00
|
|
|
{/* 通知抽屉 */}
|
|
|
|
|
<NoticeDrawer isOpen={isDrawerOpen} onOpenChange={setIsDrawerOpen} />
|
2025-11-13 08:38:25 +00:00
|
|
|
</div>
|
2025-11-28 06:31:36 +00:00
|
|
|
)
|
2025-11-13 08:38:25 +00:00
|
|
|
}
|
2025-11-28 06:31:36 +00:00
|
|
|
|
|
|
|
|
export default Notice
|