Files
expo-popcore-app/hooks/use-announcement-actions.ts
imeepos 6c17d720ca 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>
2026-01-21 14:53:03 +08:00

28 lines
725 B
TypeScript

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,
}
}