teqo-backup/src/components/campaign/dashboard/HomeSearchResultsShell.tsx
Francisco Solla fb7f85cd59 fix(OPS29): estado vazio honesto na busca global sem sugestões curadas (Closes #585)
- HomeSearchResultsShell renderiza 'Nenhuma sugestão ainda — priorize
  municípios na planilha de projeção' quando o suggest responde success
  sem hits (Início e FAB overlay compartilham o shell; SSR initialSuggest
  e POST cobertos); gateada por !isFetching para não falar sob o skeleton
- B126 e2e determinístico: pin um município priority alta claimado;
  testes OPS29 novos usam advisor sem carteira (scoped, imune a alta
  global de workers paralelos); settle de animação do overlay no B126
- unit: 3 casos novos no shell + overlap skeleton/mensagem
2026-08-10 12:54:16 -03:00

40 lines
1.7 KiB
TypeScript

'use client'
import type { ReactNode } from 'react'
import { useHomeSearch } from '@/components/campaign/dashboard/HomeSearchContext'
import { useHomeSearchResults } from '@/components/campaign/dashboard/HomeSearchResultsContext'
import { HomeSearchSuggestSkeleton } from '@/components/campaign/dashboard/HomeSearchSuggestSkeleton'
import { homeSearchHasAnyHits } from '@/lib/campaignHomeSearchHits'
import { HOME_SEARCH_SUGGEST_EMPTY_MESSAGE } from '@/lib/campaignHomeSearchMessages'
export const HomeSearchResultsShell = ({ children }: { children: ReactNode }) => {
const { query } = useHomeSearch()
const { results, resultKind, isFetching } = useHomeSearchResults()
const hasRenderableHits = results.status === 'success' && homeSearchHasAnyHits(results.data)
const showSkeleton = isFetching && !hasRenderableHits && results.status !== 'error'
const showEmpty = query.isActive && resultKind === 'search' && !hasRenderableHits
// `isFetching` keeps the message out of the debounce/skeleton window: while
// the user starts typing from an empty suggest, the skeleton covers the
// transition and the stale empty payload must not also speak (OPS29).
const showSuggestEmpty = resultKind === 'suggest' && !hasRenderableHits && !isFetching
return (
<>
{showSkeleton ? <HomeSearchSuggestSkeleton /> : null}
{!showSkeleton ? children : null}
{results.status === 'error' ? (
<p className="text-sm text-destructive" role="alert">
{results.message}
</p>
) : null}
{showEmpty ? <p className="text-sm text-muted-foreground">Nenhum resultado.</p> : null}
{showSuggestEmpty ? (
<p className="text-sm text-muted-foreground">{HOME_SEARCH_SUGGEST_EMPTY_MESSAGE}</p>
) : null}
</>
)
}