ultisuite-client/lib/contacts/use-contacts-list.ts
R3D347HR4Y 07d57f13a8
Some checks are pending
E2E / Playwright e2e (push) Waiting to run
Add Contact Avatar Features and Improve UI Components
- Introduced new ContactAvatar and ContactAvatarPicker components for enhanced avatar management in contact views.
- Updated ContactDetailView and ContactFormView to utilize the new avatar components, improving user experience when adding or editing contacts.
- Enhanced ContactHoverCard and ContactRow components to display avatars, providing a more visually appealing interface.
- Added loading and error states in ContactsListView for better user feedback during data fetching.
- Implemented a new ContactsLoadState component to handle loading and error scenarios in the contacts list.
- Updated package.json to include @formkit/auto-animate for improved UI animations.
2026-06-06 20:26:51 +02:00

39 lines
1.0 KiB
TypeScript

'use client'
import { useMemo } from 'react'
import {
useContactBooks,
useContacts,
useDefaultContactBookId,
} from '@/lib/api/hooks/use-contact-queries'
import { mapApiContactsToFullContacts } from '@/lib/api/contact-list-cache'
export function useContactsList(bookId?: string) {
const defaultBookId = useDefaultContactBookId()
const resolvedBookId = bookId ?? defaultBookId
const booksQuery = useContactBooks()
const { data: apiContacts, ...rest } = useContacts(resolvedBookId)
const contacts = useMemo(
() => mapApiContactsToFullContacts(resolvedBookId ?? '', apiContacts),
[resolvedBookId, apiContacts],
)
const isLoading = booksQuery.isLoading || (!!resolvedBookId && rest.isLoading)
const isError = booksQuery.isError || rest.isError
const error = booksQuery.error ?? rest.error
function refetch() {
void booksQuery.refetch()
void rest.refetch()
}
return {
contacts,
bookId: resolvedBookId,
...rest,
isLoading,
isError,
error,
refetch,
}
}