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:
27
hooks/use-announcement-actions.ts
Normal file
27
hooks/use-announcement-actions.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { root } from '@repo/core'
|
||||
import { AnnouncementController } from '@repo/sdk'
|
||||
import { useState } from 'react'
|
||||
|
||||
export const useAnnouncementActions = () => {
|
||||
const [markReadLoading, setMarkReadLoading] = useState(false)
|
||||
const [markReadError, setMarkReadError] = useState<Error | null>(null)
|
||||
|
||||
const markRead = async (id: string) => {
|
||||
setMarkReadLoading(true)
|
||||
setMarkReadError(null)
|
||||
try {
|
||||
const announcementController = root.get(AnnouncementController)
|
||||
await announcementController.markRead({ id })
|
||||
} catch (error) {
|
||||
setMarkReadError(error as Error)
|
||||
} finally {
|
||||
setMarkReadLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
markRead,
|
||||
markReadLoading,
|
||||
markReadError,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user