on bc37544 help sign in
bridge/src/views/Point.js
98 lines 2.7 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 { isActiveOwner, canManage, canSpawn } = useCurrentPermissions();
28 // fetch the invites for the current cursor
29 const { availableInvites } = useInvites(point);
31 const goAdmin = useCallback(() => push(names.ADMIN), [push, names]);
33 const goInvite = useCallback(() => push(names.INVITE), [push, names]);
35 const goPartiesSetPoolSize = useCallback(
36 () => push(names.PARTY_SET_POOL_SIZE),
37 [push, names]
38 );
40 const goIssuePoint = useCallback(() => push(names.ISSUE_CHILD), [
41 names.ISSUE_CHILD,
42 push,
43 ]);
45 const inviteButton = (() => {
46 switch (azimuth.getPointSize(point)) {
47 case azimuth.PointSize.Planet:
48 const availableInvitesText = matchBlinky(availableInvites);
49 return (
50 <FooterButton disabled={!isActiveOwner} onClick={goInvite}>
51 Invite <sup>{availableInvitesText} available</sup>
52 </FooterButton>
53 );
54 //
55 case azimuth.PointSize.Star:
56 return (
57 <FooterButton
58 disabled={!isActiveOwner}
59 onClick={goPartiesSetPoolSize}>
60 Manage Parties
61 </FooterButton>
62 );
63 //
64 default:
65 return null;
66 }
67 })();
69 // sync the current cursor
70 useSyncOwnedPoints([point]);
72 return (
73 <View>
74 <Passport point={Just(point)} />
75 <Grid className="pt2">
76 <Grid.Item
77 full
78 as={ForwardButton}
79 disabled={!canManage}
80 onClick={goAdmin}>
81 Admin
82 </Grid.Item>
83 <Grid.Divider />
84 {canSpawn && (
85 <>
86 <Grid.Item full as={ForwardButton} onClick={goIssuePoint}>
87 Issue Point
88 </Grid.Item>
89 <Grid.Divider />
90 </>
91 )}
92 <Grid.Item full as={BootArvoButton} disabled />
93 </Grid>
95 {inviteButton}
96 </View>
97 );