Show siblings on member page

This commit is contained in:
Pierre HUBERT 2023-08-16 08:33:07 +02:00
parent e4ca9f7e9e
commit d0cfc0e981
2 changed files with 32 additions and 0 deletions

View File

@ -195,6 +195,16 @@ export class MembersList {
children(id: number): Member[] {
return this.list.filter((m) => m.mother === id || m.father === id);
}
siblings(id: number): Member[] {
const p = this.get(id);
return this.list.filter(
(m) =>
m.id !== p?.id &&
((m.mother && m.mother === p?.mother) ||
(m.father && m.father === p?.father))
);
}
}
export class MemberApi {

View File

@ -128,6 +128,7 @@ export function FamilyMemberRoute(): React.ReactElement {
<MemberPage
member={member!}
children={family.members.children(member!.id)}
siblings={family.members.siblings(member!.id)}
creating={false}
editing={false}
onRequestDelete={deleteMember}
@ -206,6 +207,7 @@ export function MemberPage(p: {
creating: boolean;
shouldAllowLeaving?: boolean;
children?: Member[];
siblings?: Member[];
onCancel?: () => void;
onSave?: (m: Member) => void;
onRequestEdit?: () => void;
@ -628,6 +630,26 @@ export function MemberPage(p: {
</PropertiesBox>
</Grid>
)}
{/* Siblings */}
{p.siblings && (
<Grid item sm={12} md={6}>
<PropertiesBox title="Frères et sœurs">
{p.siblings.length === 0 ? (
<>Aucun frère ou sœur</>
) : (
p.siblings.map((c) => (
<RouterLink
key={c.id}
to={family.family.URL(`member/${c.id}`)}
>
<MemberItem member={c} />
</RouterLink>
))
)}
</PropertiesBox>
</Grid>
)}
</Grid>
</div>
);