on dee2cd5 help sign in
bridge/src/views/Point.js
107 lines 3.0 kB history raw
1import React, { useCallback, useMemo } 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 } from 'components/Buttons';
13import FooterButton from 'components/FooterButton';
14import { matchBlinky } from 'components/Blinky';
16import useInvites from 'lib/useInvites';
17import { useSyncOwnedPoints } from 'lib/useSyncPoints';
18import { ROUTE_NAMES } from 'lib/routeNames';
20import Actions from './Point/Actions';
21import { useWallet } from 'store/wallet';
22import usePermissionsForPoint from 'lib/usePermissionsForPoint';
24const isPlanet = point =>
25 azimuth.getPointSize(point) === azimuth.PointSize.Planet;
27export default function Point() {
28 const { push, names } = useHistory();
29 const { pointCursor } = usePointCursor();
30 const { wallet } = useWallet();
32 const point = need.point(pointCursor);
34 const { isActiveOwner, canManage } = usePermissionsForPoint(
35 // using empty string should be ok here
36 wallet.matchWith({
37 Nothing: () => '',
38 Just: p => p.value.address,
39 }),
40 point
41 );
43 // fetch the invites for the current cursor
44 const { availableInvites } = useInvites(point);
46 const showActions = Just.hasInstance(wallet);
48 const goAdmin = useCallback(() => push(names.ADMIN), [push, names]);
50 const goInvite = useCallback(() => push(names.INVITE), [push, names]);
52 const goParties = useCallback(() => push(names.INVITES_MANAGE), [
53 push,
54 names,
55 ]);
57 const inviteButton = (() => {
58 switch (azimuth.getPointSize(point)) {
59 case azimuth.PointSize.Planet:
60 const availableInvitesText = matchBlinky(availableInvites);
61 return (
62 <FooterButton disabled={!isActiveOwner} onClick={goInvite}>
63 Invite <sup>{availableInvitesText} available</sup>
64 </FooterButton>
65 );
66 //
67 case azimuth.PointSize.Star:
68 return (
69 <FooterButton disabled={!isActiveOwner} onClick={goParties}>
70 Manage parties
71 </FooterButton>
72 );
73 //
74 default:
75 return null;
76 }
77 })();
79 // sync the current cursor
80 useSyncOwnedPoints([point]);
82 return (
83 <View>
84 <Passport point={Just(point)} />
85 <Grid className="pt2">
86 <Grid.Item
87 full
88 as={ForwardButton}
89 disabled={!canManage}
90 onClick={goAdmin}>
91 Admin
92 </Grid.Item>
93 <Grid.Divider />
94 <Grid.Item full as={ForwardButton} detail="Boot your computer" disabled>
95 Boot Arvo
96 </Grid.Item>
97 {showActions && (
98 <Grid.Item full>
99 <Actions />
100 </Grid.Item>
101 )}
102 </Grid>
104 {inviteButton}
105 </View>
106 );