feat: add announcement action hooks with TDD

Add useAnnouncementActions hook for marking announcements as read and useAnnouncementUnreadCount hook for fetching unread announcement count. Both hooks follow TDD principles with complete test coverage.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
imeepos
2026-01-21 14:53:03 +08:00
parent 83c3183be8
commit 6c17d720ca
4 changed files with 255 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import { root } from '@repo/core'
import { AnnouncementController, type UnreadAnnouncementCountResult } from '@repo/sdk'
import { useState } from 'react'
export const useAnnouncementUnreadCount = () => {
const [loading, setLoading] = useState(false)
const [error, setError] = useState<Error | null>(null)
const [data, setData] = useState<UnreadAnnouncementCountResult>()
const refetch = async () => {
setLoading(true)
setError(null)
try {
const announcementController = root.get(AnnouncementController)
const result = await announcementController.getUnreadCount()
setData(result)
} catch (err) {
setError(err as Error)
} finally {
setLoading(false)
}
}
return {
data,
loading,
error,
refetch,
}
}