import { createContext, use, useState } from "react"; import { Transactions } from "./transactions"; import { View, Text } from "react-native"; import { Settings } from "./settings"; import { useKeyboard } from "./useKeyboard"; import type { AuthData } from "@money/shared/auth"; const PAGES = { '/': { screen: , key: "1", }, '/settings': { screen: , key: "2", children: { "/accounts": {}, "/family": {}, } }, }; type Join = `${A}${B}` extends `${infer X}` ? X : never; type ChildRoutes = { [K in keyof Children & string]: K extends `/${string}` ? Join : never; }[keyof Children & string]; type Routes = { [K in keyof T & string]: | K | (T[K] extends { children: infer C } ? ChildRoutes : never) }[keyof T & string]; export type Route = Routes; interface RouterContextType { auth: AuthData | null; route: Route; setRoute: (route: Route) => void; } export const RouterContext = createContext({ auth: null, route: '/', setRoute: () => {} }); type AppProps = { auth: AuthData | null; route: Route; setRoute: (page: Route) => void; } export function App({ auth, route, setRoute }: AppProps) { return
} function Main() { const { route, setRoute } = use(RouterContext); useKeyboard((key) => { const screen = Object.entries(PAGES) .find(([, screen]) => screen.key == key.name); if (!screen) return; const [route] = screen as [Route, never]; setRoute(route); }); const match = route in PAGES ? (route as keyof typeof PAGES) : (Object.keys(PAGES).sort((a, b) => b.length - a.length).find(p => route.startsWith(p)) as keyof typeof PAGES); return {PAGES[match].screen} }