on 08b82bf help sign in
bridge/src/views/Point.js
106 lines 3.1 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 history = useHistory();
29 const { pointCursor } = usePointCursor();
30 const { wallet } = useWallet();
32 const point = need.point(pointCursor);
34 const { isOwner, 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(() => history.push(ROUTE_NAMES.ADMIN), [history]);
50 const goInvite = useCallback(() => history.push(ROUTE_NAMES.INVITE), [
51 history,
52 ]);
54 const inviteButton = useMemo(() => {
55 switch (azimuth.getPointSize(point)) {
56 case azimuth.PointSize.Planet:
57 const availableInvitesText = matchBlinky(availableInvites);
58 const goInvite = () => history.push(ROUTE_NAMES.INVITE);
59 return (
60 <FooterButton disabled={!isOwner} onClick={goInvite}>
61 Invite <sup>{availableInvitesText} available</sup>
62 </FooterButton>
63 );
64 //
65 case azimuth.PointSize.Star:
66 const goParties = () => history.push(ROUTE_NAMES.INVITES_MANAGE);
67 return (
68 <FooterButton disabled={!isOwner} onClick={goParties}>
69 Manage parties
70 </FooterButton>
71 );
72 //
73 default:
74 return null;
75 }
76 }, [point, history, isOwner, availableInvites]);
78 // sync the current cursor
79 useSyncOwnedPoints([point]);
81 return (
82 <View>
83 <Passport point={Just(point)} />
84 <Grid className="pt2">
85 <Grid.Item
86 full
87 as={ForwardButton}
88 disabled={!canManage}
89 onClick={goAdmin}>
90 Admin
91 </Grid.Item>
92 <Grid.Divider />
93 <Grid.Item full as={ForwardButton} detail="Boot your computer" disabled>
94 Boot Arvo
95 </Grid.Item>
96 {showActions && (
97 <Grid.Item full>
98 <Actions />
99 </Grid.Item>
100 )}
101 </Grid>
103 {inviteButton}
104 </View>
105 );