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