Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/contacts/useContactsPagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export function useContactsPagination(workspaceId: string) {

try {
let data: ContactListItem[] = [];
const countData: { count: number } | null = null;

if (f.search.trim()) {
// Use full-text search RPC (handles unaccent + trigram)
Expand All @@ -82,6 +81,9 @@ export function useContactsPagination(workspaceId: string) {
});
if (error) throw error;
data = (searchData ?? []).map(sanitizeRow);
// TODO: search_contacts RPC não retorna count exato. Por ora, setamos total = qtd carregada
// (acumulado em loadMore). Resolver criando count_search_contacts() RPC.
setTotal(data.length);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the RPC's total_count for search totals

When a search matches more than one page, setting total to only data.length makes the displayed count under-report the real result set and then change as the user scrolls (for example 200 matches show as 50 after the first page). The RPC overload being called here is the search_term/page_size one, and both the generated Supabase types and SQL function expose total_count on each returned row (src/integrations/supabase/types.ts:14944-14972, supabase/migrations-from-lovable/03_functions.sql:4430-4467), so the hook can keep the exact search total instead of replacing it with the loaded-page count.

Useful? React with 👍 / 👎.

} else {
// Standard query with filters
let query = dbFrom('contacts')
Expand Down Expand Up @@ -138,6 +140,8 @@ export function useContactsPagination(workspaceId: string) {
});
if (error) throw error;
data = (searchData ?? []).map(sanitizeRow);
// Search RPC: acumular total conforme loadMore traz mais resultados
setTotal((prev) => prev + data.length);
} else {
let query = dbFrom('contacts')
.select('id, name, phone, email, company, tags, channel, avatar_url, last_seen_at, created_at')
Expand Down
Loading