import { Text, View, Pressable } from "react-native"; import { use, useState, type ReactNode } from "react"; import { RouterContext, type Route } from "."; import { General } from "./settings/general"; import { Accounts } from "./settings/accounts"; import { Family } from "./settings/family"; import { useKeyboard } from "./useKeyboard"; import { Modal } from "react-native-opentui"; type SettingsRoute = Extract; const TABS = { "/settings": { label: "💽 General", screen: }, "/settings/accounts": { label: "🏦 Bank Accounts", screen: }, "/settings/family": { label: "👑 Family", screen: }, } as const satisfies Record; type Tab = keyof typeof TABS; export function Settings() { const { route, setRoute } = use(RouterContext); useKeyboard((key) => { if (key.name == 'h') { const currentIdx = Object.entries(TABS).findIndex(([tabRoute, _]) => tabRoute == route) const routes = Object.keys(TABS) as SettingsRoute[]; const last = routes[currentIdx - 1] if (!last) return; setRoute(last); } else if (key.name == 'l') { const currentIdx = Object.entries(TABS).findIndex(([tabRoute, _]) => tabRoute == route) const routes = Object.keys(TABS) as SettingsRoute[]; const next = routes[currentIdx + 1] if (!next) return; setRoute(next); } }, [route]); return ( {Object.entries(TABS).map(([tabRoute, tab]) => { const isSelected = tabRoute == route; return ( setRoute(tabRoute as SettingsRoute)}> {tab.label} ); })} {TABS[route as Tab].screen} ); }