on 8d566ea help sign in
bridge/src/views/UrbitID.js
83 lines 2.1 kB history raw
1import React from 'react';
2import { Grid } from 'indigo-react';
4import { useHistory } from 'store/history';
6import useCurrentPointName from 'lib/useCurrentPointName';
7import useRouter from 'lib/useRouter';
8import { LocalRouterProvider } from 'lib/LocalRouter';
10import View from 'components/View';
11import Crumbs from 'components/Crumbs';
12import NavHeader from 'components/NavHeader';
14import UrbitIDHome from './UrbitID/Home';
15import SigilGenerator from './UrbitID/SigilGenerator';
16import DownloadKeys from './UrbitID/DownloadKeys';
17import SetProxy from './UrbitID/SetProxy';
18import ResetKeys from './UrbitID/ResetKeys';
20const NAMES = {
21 HOME: 'HOME',
22 SIGIL_GENERATOR: 'SIGIL_GENERATOR',
23 DOWNLOAD_KEYS: 'DOWNLOAD_KEYS',
24 SET_PROXY: 'SET_PROXY',
25 RESET_KEYS: 'RESET_KEYS',
26};
28const VIEWS = {
29 [NAMES.HOME]: UrbitIDHome,
30 [NAMES.SIGIL_GENERATOR]: SigilGenerator,
31 [NAMES.DOWNLOAD_KEYS]: DownloadKeys,
32 [NAMES.RESET_KEYS]: ResetKeys,
33 [NAMES.SET_PROXY]: SetProxy,
34};
36const humanizeName = name => {
37 switch (name) {
38 case NAMES.SIGIL_GENERATOR:
39 return 'Sigil';
40 case NAMES.DOWNLOAD_KEYS:
41 return 'Download Keys';
42 case NAMES.SET_PROXY:
43 return 'Set Key';
44 case NAMES.RESET_KEYS:
45 return 'Reset Keys';
46 default:
47 return undefined;
48 }
49};
51export default function UrbitOS() {
52 const history = useHistory();
53 const name = useCurrentPointName();
55 const { Route, ...router } = useRouter({
56 names: NAMES,
57 views: VIEWS,
58 initialRoutes: [{ key: NAMES.HOME }],
59 });
61 const last = router.peek().key;
62 const homeAction = last === NAMES.HOME ? undefined : () => history.pop();
63 const lastCrumb = homeAction ? [{ text: humanizeName(last) }] : [];
65 return (
66 <View pop={router.pop} inset>
67 <NavHeader>
68 <Crumbs
69 routes={[
70 { text: name, action: () => history.pop() },
71 { text: 'Urbit ID', action: homeAction },
72 ...lastCrumb,
73 ]}
74 />
75 </NavHeader>
77 <LocalRouterProvider value={router}>
78 <Grid className="mb4"></Grid>
79 <Route />
80 </LocalRouterProvider>
81 </View>
82 );