teqo-backup/src/lib/homeSearchNearestMunicipalityMerge.ts
Cursor Agent fe2748c5ab
B117 — prefix nearest município in global search suggest (geo)
- loadHomeSearchSuggestions returns scopeMunicipalities for client merge
- useHomeSearchNearestMunicipality prompts once per session (B14 key)
- mergeHomeSearchNearestMunicipality prefixes hit without geo copy
- HomeSearchMunicipalityGroup wires suggest reorder for Início + drawer

Closes #204

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
2026-08-02 00:56:47 +00:00

20 lines
798 B
TypeScript

import type { HomeSearchMunicipalityHit } from '@/lib/campaignHomeSearchHits'
/**
* B117 — prefix the nearest in-scope município on suggest, deduping the server list.
* The hit uses the normal suggest shape — no geo reason or distance metadata.
*/
export const mergeHomeSearchNearestMunicipality = (input: {
nearestSlug: string | null | undefined
serverHits: readonly HomeSearchMunicipalityHit[]
hitBySlug: ReadonlyMap<string, HomeSearchMunicipalityHit>
}): HomeSearchMunicipalityHit[] => {
const slug = input.nearestSlug?.trim()
if (!slug) return [...input.serverHits]
const nearestHit = input.hitBySlug.get(slug)
if (!nearestHit) return [...input.serverHits]
const withoutDup = input.serverHits.filter((hit) => hit.slug !== slug)
return [nearestHit, ...withoutDup]
}