import React from "react"; import { Outlet } from "react-router-dom"; import { CoupleApi, CouplesList } from "../../api/genealogy/CoupleApi"; import { MemberApi, MembersList } from "../../api/genealogy/MemberApi"; import { AsyncWidget } from "../AsyncWidget"; import { useFamily } from "../BaseFamilyRoute"; interface GenealogyContext { members: MembersList; couples: CouplesList; reloadMembersList: () => Promise; reloadCouplesList: () => Promise; } const GenealogyContextK = React.createContext(null); export function BaseGenealogyRoute(): React.ReactElement { const family = useFamily(); const [members, setMembers] = React.useState(null); const [couples, setCouples] = React.useState(null); const loadKey = React.useRef(1); const loadPromise = React.useRef<() => void>(null); const load = async () => { setMembers(await MemberApi.GetEntireList(family.familyId)); setCouples(await CoupleApi.GetEntireList(family.familyId)); }; const onReload = async () => { loadKey.current += 1; setMembers(null); setCouples(null); return new Promise((res, _rej) => { loadPromise.current = () => res(); }); }; return ( { if (loadPromise.current != null) { loadPromise.current?.(); loadPromise.current = null; } return ( ); }} /> ); } export function useGenealogy(): GenealogyContext { return React.useContext(GenealogyContextK)!; }