on dffcebf help sign in
bridge/src/views/Point.js
85 lines 2.4 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 } = 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 inviteButton = (() => {
41 switch (azimuth.getPointSize(point)) {
42 case azimuth.PointSize.Planet:
43 const availableInvitesText = matchBlinky(availableInvites);
44 return (
45 <FooterButton disabled={!isActiveOwner} onClick={goInvite}>
46 Invite <sup>{availableInvitesText} available</sup>
47 </FooterButton>
48 );
49 //
50 case azimuth.PointSize.Star:
51 return (
52 <FooterButton
53 disabled={!isActiveOwner}
54 onClick={goPartiesSetPoolSize}>
55 Manage Parties
56 </FooterButton>
57 );
58 //
59 default:
60 return null;
61 }
62 })();
64 // sync the current cursor
65 useSyncOwnedPoints([point]);
67 return (
68 <View>
69 <Passport point={Just(point)} />
70 <Grid className="pt2">
71 <Grid.Item
72 full
73 as={ForwardButton}
74 disabled={!canManage}
75 onClick={goAdmin}>
76 Admin
77 </Grid.Item>
78 <Grid.Divider />
79 <Grid.Item full as={BootArvoButton} disabled />
80 </Grid>
82 {inviteButton}
83 </View>
84 );