- CampaignTable/CampaignTableHead: colunas como dado (id, head island, cell, seams B17 mandatory/defaultVisible); colSpan derivado - CampaignListFooter: contagem + paginacao compartilhadas - MunicipalityList reescrita sobre column defs; cards mobile inalterados - municipalityUi.ts (765/59 exports) dividido: municipalityListUrl / municipalityListFilters / municipalityLabels / municipalitySignal; contrato de URL byte-identico (pins verdes) - B16+ absorvido: useOptimistic no HeaderFilter (onNavigate dentro da transition), hrefs de opcao via serializador canonico confiavel (1 serializacao por opcao, pin de byte-igualdade), facet de municipio como slugs rotulados no cliente (-20KB), facets no mesmo Promise.all (seed por promise), catalogo DRY, clearMunicipalityListFilters - timeout explicito no int test de facets (2 bundles full-scope sob suite 47-way)
49 lines
1.9 KiB
TypeScript
49 lines
1.9 KiB
TypeScript
/**
|
|
* E9 "frescor" — signal freshness for the allocation queue. One rule shared by
|
|
* the server ordering (`municipalityPageData.ts`) and the list cell, so
|
|
* "há N dias" never disagrees with the position in the queue. Split out of the
|
|
* former `municipalityUi.ts` in Pass 2 W1.
|
|
*/
|
|
import { latestIsoTimestamp } from '@/utilities/campaignTime'
|
|
|
|
/**
|
|
* The last time ANYBODY recorded something here: a staff update or a
|
|
* leadership pledge declaration/estimate.
|
|
*/
|
|
export const resolveMunicipalityLastSignalAt = (
|
|
lastUpdateAt: string | null,
|
|
lastPledgeAt: string | null,
|
|
): string | null => latestIsoTimestamp(lastUpdateAt, lastPledgeAt)
|
|
|
|
/**
|
|
* Days since the last signal, floored. The research report only says a
|
|
* commitment left untouched "for weeks" is worth less, so the threshold below
|
|
* is a convention (3 weeks), not a measured decay curve.
|
|
*/
|
|
export const MUNICIPALITY_COLD_SIGNAL_DAYS = 21
|
|
|
|
export const municipalitySignalAgeInDays = (
|
|
lastSignalAt: string | null,
|
|
now: Date = new Date(),
|
|
): number | null => {
|
|
if (!lastSignalAt) return null
|
|
const elapsed = now.getTime() - new Date(lastSignalAt).getTime()
|
|
if (Number.isNaN(elapsed)) return null
|
|
return Math.max(0, Math.floor(elapsed / 86_400_000))
|
|
}
|
|
|
|
export const isMunicipalitySignalCold = (ageInDays: number | null): boolean =>
|
|
ageInDays === null || ageInDays >= MUNICIPALITY_COLD_SIGNAL_DAYS
|
|
|
|
/**
|
|
* "há 3 dias" / "hoje" / "Sem sinal" — dense cell copy for the queue.
|
|
* Deliberately not `formatRelativeAge`: its `numeric: 'auto'` yields "ontem"/
|
|
* "anteontem" and minute/hour granularity, which breaks both the day-based
|
|
* cold threshold and the tabular-nums scan down the column.
|
|
*/
|
|
export const formatMunicipalitySignalAgeLabel = (ageInDays: number | null): string => {
|
|
if (ageInDays === null) return 'Sem sinal'
|
|
if (ageInDays === 0) return 'hoje'
|
|
if (ageInDays === 1) return 'há 1 dia'
|
|
return `há ${ageInDays} dias`
|
|
}
|