Add BahiaMap surfaces on nuclei list, detail, and geral dashboard with server-side choropleth aggregation, lazy geometry loading (B5 F1), and roadmap plans for A7 F4, B5 F3, and B6 scale debts.
29 lines
996 B
TypeScript
29 lines
996 B
TypeScript
import type { Payload } from 'payload'
|
|
|
|
import type { CampaignUser, User } from '@/payload-types'
|
|
import { loadBaseline2022VotesByCityNames } from '@/utilities/nucleusElectoralBaseline'
|
|
import {
|
|
buildNucleusChoroplethBundleFromResolved,
|
|
resolveChoroplethNuclei,
|
|
type NucleusChoroplethBundle,
|
|
type NucleusChoroplethNucleus,
|
|
} from '@/utilities/nucleusChoropleth'
|
|
|
|
type ChoroplethReader = CampaignUser | User
|
|
|
|
export const loadNucleusChoroplethBundle = async (
|
|
payload: Pick<Payload, 'find'>,
|
|
user: ChoroplethReader,
|
|
nuclei: readonly NucleusChoroplethNucleus[],
|
|
): Promise<NucleusChoroplethBundle> => {
|
|
const resolved = resolveChoroplethNuclei(nuclei)
|
|
const cityNames = [
|
|
...new Set(resolved.flatMap(({ cities }) => cities)),
|
|
]
|
|
const baselineVotesByCity =
|
|
cityNames.length > 0
|
|
? await loadBaseline2022VotesByCityNames(payload, user, cityNames)
|
|
: new Map<string, number>()
|
|
|
|
return buildNucleusChoroplethBundleFromResolved(resolved, baselineVotesByCity)
|
|
}
|