Files
expo-popcore-app/hooks/use-message-unread-count.ts
imeepos 83c3183be8 feat: add message action hooks with TDD
Implement useMessageActions and useMessageUnreadCount hooks following strict TDD principles (RED → GREEN → REFACTOR).

useMessageActions provides:
- markRead(id) - mark single message as read
- batchMarkRead(ids) - batch mark messages as read
- deleteMessage(id) - delete message
- Independent loading/error states for each operation

useMessageUnreadCount provides:
- Fetch total unread count and counts by message type
- refetch() method for manual refresh
- loading and error state management

All operations use MessageController from SDK with proper error handling.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-21 14:48:27 +08:00

31 lines
735 B
TypeScript

import { root } from '@repo/core'
import { MessageController, type UnreadCountResult } from '@repo/sdk'
import { useState } from 'react'
export const useMessageUnreadCount = () => {
const [loading, setLoading] = useState(false)
const [error, setError] = useState<Error | null>(null)
const [data, setData] = useState<UnreadCountResult>()
const refetch = async () => {
setLoading(true)
setError(null)
try {
const messageController = root.get(MessageController)
const result = await messageController.getUnreadCount()
setData(result)
} catch (err) {
setError(err as Error)
} finally {
setLoading(false)
}
}
return {
data,
loading,
error,
refetch,
}
}