on da154dd help sign in
bridge/src/views/Point.js
123 lines 3.3 kB history raw
1import React, { useCallback } from 'react';
2import { Just } from 'folktale/maybe';
3import { Grid } from 'indigo-react';
4import { azimuth } from 'azimuth-js';
6import { usePointCursor } from 'store/pointCursor';
8import View from 'components/View';
9import Greeting from 'components/Greeting';
10import Passport from 'components/Passport';
11import { ForwardButton, BootArvoButton } from 'components/Buttons';
12import { matchBlinky } from 'components/Blinky';
13import SigilDownloader from 'components/SigilDownloader';
15import * as need from 'lib/need';
16import useInvites from 'lib/useInvites';
17import { useSyncOwnedPoints } from 'lib/useSyncPoints';
18import useCurrentPermissions from 'lib/useCurrentPermissions';
19import { useLocalRouter } from 'lib/LocalRouter';
21export default function Point() {
22 const { pop, push, names } = useLocalRouter();
23 const { pointCursor } = usePointCursor();
25 const point = need.point(pointCursor);
27 const {
28 isParent,
29 isActiveOwner,
30 canManage,
31 canSpawn,
32 } = useCurrentPermissions();
34 // fetch the invites for the current cursor
35 const { availableInvites } = useInvites(point);
37 const goAdmin = useCallback(() => push(names.ADMIN), [push, names]);
39 const goInvite = useCallback(() => push(names.INVITE), [push, names]);
41 const goPartiesSetPoolSize = useCallback(
42 () => push(names.PARTY_SET_POOL_SIZE),
43 [push, names]
44 );
46 const goIssuePoint = useCallback(() => push(names.ISSUE_CHILD), [
47 names.ISSUE_CHILD,
48 push,
49 ]);
51 const inviteButton = (() => {
52 switch (azimuth.getPointSize(point)) {
53 case azimuth.PointSize.Planet:
54 const availableInvitesText = matchBlinky(availableInvites);
55 return (
56 <>
57 <Grid.Item
58 full
59 as={ForwardButton}
60 disabled={!isActiveOwner}
61 onClick={goInvite}>
62 Invite <sup>{availableInvitesText}</sup>
63 </Grid.Item>
64 <Grid.Divider />
65 </>
66 );
67 //
68 case azimuth.PointSize.Star:
69 return (
70 <>
71 <Grid.Item
72 full
73 as={ForwardButton}
74 disabled={!isActiveOwner}
75 onClick={goPartiesSetPoolSize}>
76 Manage Invite Pools
77 </Grid.Item>
78 <Grid.Divider />
79 </>
80 );
81 //
82 default:
83 return null;
84 }
85 })();
87 // sync the current cursor
88 useSyncOwnedPoints([point]);
90 return (
91 <View pop={pop} inset>
92 <Greeting point={point} />
93 <SigilDownloader point={point}>
94 <Passport point={Just(point)} />
95 </SigilDownloader>
96 <Grid className="pt2">
97 {inviteButton}
98 <Grid.Item
99 full
100 as={ForwardButton}
101 disabled={!canManage}
102 onClick={goAdmin}>
103 Admin
104 </Grid.Item>
105 <Grid.Divider />
106 {isParent && (
107 <>
108 <Grid.Item
109 full
110 as={ForwardButton}
111 disabled={!canSpawn}
112 onClick={goIssuePoint}>
113 Issue Point
114 </Grid.Item>
115 <Grid.Divider />
116 </>
117 )}
118 <Grid.Item full as={BootArvoButton} />
119 <Grid.Divider />
120 </Grid>
121 </View>
122 );