diff --git a/geneit_app/src/App.tsx b/geneit_app/src/App.tsx index 3543794..6e3d5e6 100644 --- a/geneit_app/src/App.tsx +++ b/geneit_app/src/App.tsx @@ -13,6 +13,8 @@ import { BaseAuthenticatedPage } from "./widgets/BaseAuthenticatedPage"; import { BaseLoginPage } from "./widgets/BaseLoginpage"; import { DeleteAccountRoute } from "./routes/DeleteAccountRoute"; import { FamiliesListRoute } from "./routes/FamiliesListRoute"; +import { BaseFamilyRoute } from "./widgets/BaseFamilyRoute"; +import { FamilyHomeRoute } from "./routes/family/FamilyHomeRoute"; interface AuthContext { signedIn: boolean; @@ -41,6 +43,10 @@ export function App(): React.ReactElement { }> } /> } /> + }> + } /> + } /> + } /> ) : ( diff --git a/geneit_app/src/api/FamilyApi.ts b/geneit_app/src/api/FamilyApi.ts index 9c26432..785b9b6 100644 --- a/geneit_app/src/api/FamilyApi.ts +++ b/geneit_app/src/api/FamilyApi.ts @@ -111,6 +111,18 @@ export class FamilyApi { ).data.map((f: FamilyAPI) => new Family(f)); } + /** + * Get information about a single family + */ + static async GetSingle(id: number): Promise { + const res = await APIClient.exec({ + method: "GET", + uri: `/family/${id}`, + }); + + return new Family(res.data); + } + /** * Attempt to leave a family */ diff --git a/geneit_app/src/routes/family/FamilyHomeRoute.tsx b/geneit_app/src/routes/family/FamilyHomeRoute.tsx new file mode 100644 index 0000000..93b3be0 --- /dev/null +++ b/geneit_app/src/routes/family/FamilyHomeRoute.tsx @@ -0,0 +1,3 @@ +export function FamilyHomeRoute(): React.ReactElement { + return

family home

; +} diff --git a/geneit_app/src/widgets/BaseFamilyRoute.tsx b/geneit_app/src/widgets/BaseFamilyRoute.tsx new file mode 100644 index 0000000..5e14c7f --- /dev/null +++ b/geneit_app/src/widgets/BaseFamilyRoute.tsx @@ -0,0 +1,54 @@ +import { Outlet, useParams } from "react-router-dom"; +import { Family, FamilyApi } from "../api/FamilyApi"; +import React from "react"; +import { AsyncWidget } from "./AsyncWidget"; + +interface FamilyContext { + family: Family; + reloadFamilyInfo: () => void; +} + +const FamilyContextK = React.createContext(null); + +export function BaseFamilyRoute(): React.ReactElement { + const { familyId } = useParams(); + + const [family, setFamily] = React.useState(null); + + const loadKey = React.useRef(1); + + const load = async () => { + setFamily(await FamilyApi.GetSingle(Number(familyId))); + }; + + const onReload = () => { + loadKey.current += 1; + setFamily(null); + }; + + return ( + ( + +
+

base family route

+ +
+
+ )} + /> + ); +} + +export function useFamily(): FamilyContext { + return React.useContext(FamilyContextK)!; +}