on 729283f help sign in
bridge/src/views/Point.js
107 lines 2.8 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 FooterButton from 'components/FooterButton';
14import { matchBlinky } from 'components/Blinky';
16import useInvites from 'lib/useInvites';
17import { useSyncOwnedPoints } from 'lib/useSyncPoints';
18import useCurrentPermissions from 'lib/useCurrentPermissions';
20export default function Point() {
21 const { push, names } = useHistory();
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 <FooterButton disabled={!isActiveOwner} onClick={goInvite}>
56 Invite <sup>{availableInvitesText} available</sup>
57 </FooterButton>
58 );
59 //
60 case azimuth.PointSize.Star:
61 return (
62 <FooterButton
63 disabled={!isActiveOwner}
64 onClick={goPartiesSetPoolSize}>
65 Manage Parties
66 </FooterButton>
67 );
68 //
69 default:
70 return null;
71 }
72 })();
74 // sync the current cursor
75 useSyncOwnedPoints([point]);
77 return (
78 <View>
79 <Passport point={Just(point)} />
80 <Grid className="pt2">
81 <Grid.Item
82 full
83 as={ForwardButton}
84 disabled={!canManage}
85 onClick={goAdmin}>
86 Admin
87 </Grid.Item>
88 <Grid.Divider />
89 {isParent && (
90 <>
91 <Grid.Item
92 full
93 as={ForwardButton}
94 disabled={!canSpawn}
95 onClick={goIssuePoint}>
96 Issue Point
97 </Grid.Item>
98 <Grid.Divider />
99 </>
100 )}
101 <Grid.Item full as={BootArvoButton} disabled />
102 </Grid>
104 {inviteButton}
105 </View>
106 );