qazaq-legacy-foundation-web/src/lib/home-model.ts
Peppa ab5a495f2f
Some checks failed
peppa/install install: failure за 0с
ci / checks (pull_request) Failing after 3s
deploy / deploy (pull_request) Successful in 1m46s
QLFW-4: главная страница фонда (Next.js, Tailwind, Payload)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 15:35:52 +05:00

42 lines
1.8 KiB
TypeScript

import type { Dict } from '@/i18n'
export type CmsItem = { title?: string | null; text?: string | null }
export type CmsHome = {
mission?: string | null
directions?: CmsItem[] | null
projects?: CmsItem[] | null
collaboration?: string | null
contactEmail?: string | null
}
export type CmsNews = { id: string | number; title: string; summary?: string | null; kind?: string | null; date: string; place?: string | null }
export type Card = { title: string; text: string | null; tbc: boolean }
export type HomeModel = {
mission: { text: string; tbc: boolean }
directions: Card[]
projects: Card[]
news: CmsNews[]
collaboration: { text: string; email: string | null }
}
const clean = (v?: string | null) => (v && v.trim() ? v.trim() : null)
/** Собирает данные главной: пустое подтверждённое поле → «нужно уточнить», блоки без данных — пустые списки. */
export function buildHomeModel(cms: CmsHome | null, news: CmsNews[], t: Dict): HomeModel {
const cmsDirs = (cms?.directions ?? []).filter((d) => clean(d.title))
const directions: Card[] = cmsDirs.length
? cmsDirs.map((d) => ({ title: d.title!.trim(), text: clean(d.text), tbc: !clean(d.text) }))
: t.directions.items.map((d) => ({ title: d.title, text: d.text, tbc: true }))
const projects: Card[] = (cms?.projects ?? [])
.filter((p) => clean(p.title))
.map((p) => ({ title: p.title!.trim(), text: clean(p.text), tbc: !clean(p.text) }))
const mission = clean(cms?.mission)
return {
mission: { text: mission ?? t.mission.text, tbc: !mission },
directions,
projects,
news,
collaboration: { text: clean(cms?.collaboration) ?? t.collaboration.text, email: clean(cms?.contactEmail) },
}
}