20 lines
624 B
TypeScript
20 lines
624 B
TypeScript
import type { Node, NodeDayGroup } from "~/types"
|
|
import { dayKey } from "./dayKey"
|
|
import { dayLabel } from "./dayLabel"
|
|
|
|
/** Split a node's children into an undated bucket + day-labelled groups. */
|
|
export const groupChildren = (children: Node[]): NodeDayGroup[] => {
|
|
const groups: NodeDayGroup[] = []
|
|
let curKey = ""
|
|
for (const ev of children) {
|
|
const start = ev.event.startDate
|
|
if (!start) continue
|
|
const key = dayKey(start)
|
|
if (key !== curKey) {
|
|
groups.push({ label: dayLabel(start), events: [] })
|
|
curKey = key
|
|
}
|
|
groups[groups.length - 1]!.events.push(ev)
|
|
}
|
|
return groups
|
|
}
|