on d1230bb help sign in
bridge/src/views/Point.js
82 lines 2.3 kB history raw
1import React, { useCallback } from 'react';
2import { Just } from 'folktale/maybe';
3import * as need from 'lib/need';
4import { Grid } from 'indigo-react';
6import { usePointCursor } from 'store/pointCursor';
7import { usePointCache } from 'store/pointCache';
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';
24export default function Point() {
25 const history = useHistory();
26 const { pointCursor } = usePointCursor();
27 const { wallet } = useWallet();
29 const point = need.point(pointCursor);
31 const { canManage } = usePermissionsForPoint(
32 // using empty string should be ok here
33 wallet.matchWith({
34 Nothing: () => '',
35 Just: p => p.value.address,
36 }),
37 point
38 );
40 // fetch the invites for the current cursor
41 const { availableInvites } = useInvites(point);
42 const availableInvitesText = matchBlinky(availableInvites);
44 const showActions = Just.hasInstance(wallet);
46 const goAdmin = useCallback(() => history.push(ROUTE_NAMES.ADMIN), [history]);
48 const goInvite = useCallback(() => history.push(ROUTE_NAMES.INVITE), [
49 history,
50 ]);
52 // sync the current cursor
53 useSyncOwnedPoints([point]);
55 return (
56 <View>
57 <Passport point={Just(point)} />
58 <Grid className="pt2">
59 <Grid.Item
60 full
61 as={ForwardButton}
62 disabled={!canManage}
63 onClick={goAdmin}>
64 Admin
65 </Grid.Item>
66 <Grid.Divider />
67 <Grid.Item full as={ForwardButton} detail="Boot your computer" disabled>
68 Boot Arvo
69 </Grid.Item>
70 {showActions && (
71 <Grid.Item full>
72 <Actions />
73 </Grid.Item>
74 )}
75 </Grid>
77 <FooterButton disabled={!canManage} onClick={goInvite}>
78 Invite <sup>{availableInvitesText} available</sup>
79 </FooterButton>
80 </View>
81 );