diff --git a/geneit_app/src/utils/family_tree.ts b/geneit_app/src/utils/family_tree.ts index ec53aa1..e9dba4d 100644 --- a/geneit_app/src/utils/family_tree.ts +++ b/geneit_app/src/utils/family_tree.ts @@ -1,5 +1,5 @@ import { Couple, CouplesList } from "../api/CoupleApi"; -import { Member, MembersList } from "../api/MemberApi"; +import { Member, MembersList, dateTimestamp } from "../api/MemberApi"; export interface CoupleInformation { couple: Couple; @@ -67,13 +67,25 @@ export function buildDescendingTree( member_couples.push({ couple: c, member: pair!, - down: c_children.map((c) => buildDescendingTree(c.id, members, couples)), + down: sortChildren( + c_children.map((c) => buildDescendingTree(c.id, members, couples)) + ), }); } return { member: member, - down: children.map((c) => buildDescendingTree(c.id, members, couples)), + down: sortChildren( + children.map((c) => buildDescendingTree(c.id, members, couples)) + ), couples: member_couples, }; } + +function sortChildren(n: FamilyTreeNode[]): FamilyTreeNode[] { + n.sort( + (a, b) => + dateTimestamp(a.member.dateOfBirth) - dateTimestamp(b.member.dateOfBirth) + ); + return n; +}