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:
30
hooks/use-announcement-unread-count.ts
Normal file
30
hooks/use-announcement-unread-count.ts
Normal 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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user