on 261ea40 help sign in
bridge/src/views/Point.js
118 lines 3.0 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';
8import { useHistory } from 'store/history';
10import View from 'components/View';
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';
19export default function Point() {
20 const { push, names } = useHistory();
21 const { pointCursor } = usePointCursor();
23 const point = need.point(pointCursor);
25 const {
26 isParent,
27 isActiveOwner,
28 canManage,
29 canSpawn,
30 } = useCurrentPermissions();
32 // fetch the invites for the current cursor
33 const { availableInvites } = useInvites(point);
35 const goAdmin = useCallback(() => push(names.ADMIN), [push, names]);
37 const goInvite = useCallback(() => push(names.INVITE), [push, names]);
39 const goPartiesSetPoolSize = useCallback(
40 () => push(names.PARTY_SET_POOL_SIZE),
41 [push, names]
42 );
44 const goIssuePoint = useCallback(() => push(names.ISSUE_CHILD), [
45 names.ISSUE_CHILD,
46 push,
47 ]);
49 const inviteButton = (() => {
50 switch (azimuth.getPointSize(point)) {
51 case azimuth.PointSize.Planet:
52 const availableInvitesText = matchBlinky(availableInvites);
53 return (
54 <>
55 <Grid.Item
56 full
57 as={ForwardButton}
58 disabled={!isActiveOwner}
59 onClick={goInvite}>
60 Invite <sup>{availableInvitesText}</sup>
61 </Grid.Item>
62 <Grid.Divider />
63 </>
64 );
65 //
66 case azimuth.PointSize.Star:
67 return (
68 <>
69 <Grid.Item
70 full
71 as={ForwardButton}
72 disabled={!isActiveOwner}
73 onClick={goPartiesSetPoolSize}>
74 Manage Parties
75 </Grid.Item>
76 <Grid.Divider />
77 </>
78 );
79 //
80 default:
81 return null;
82 }
83 })();
85 // sync the current cursor
86 useSyncOwnedPoints([point]);
88 return (
89 <View>
90 <Passport point={Just(point)} />
91 <Grid className="pt2">
92 {inviteButton}
93 <Grid.Item
94 full
95 as={ForwardButton}
96 disabled={!canManage}
97 onClick={goAdmin}>
98 Admin
99 </Grid.Item>
100 <Grid.Divider />
101 {isParent && (
102 <>
103 <Grid.Item
104 full
105 as={ForwardButton}
106 disabled={!canSpawn}
107 onClick={goIssuePoint}>
108 Issue Point
109 </Grid.Item>
110 <Grid.Divider />
111 </>
112 )}
113 <Grid.Item full as={BootArvoButton} disabled />
114 <Grid.Divider />
115 </Grid>
116 </View>
117 );