on master help sign in
Display invite button according to context
81c4530Fang
src/views/Point.js+31−6
@@ -1,7 +1,8 @@
1−import React, { useCallback } from 'react';
1+import React, { useCallback, useMemo } from 'react';
2import { Just } from 'folktale/maybe';
2import { Just } from 'folktale/maybe';
3import * as need from 'lib/need';
3import * as need from 'lib/need';
4import { Grid } from 'indigo-react';
4import { Grid } from 'indigo-react';
5+import { azimuth } from 'azimuth-js';
5
6
6import { usePointCursor } from 'store/pointCursor';
7import { usePointCursor } from 'store/pointCursor';
7import { useHistory } from 'store/history';
8import { useHistory } from 'store/history';
@@ -20,6 +21,9 @@ import Actions from './Point/Actions';
20import { useWallet } from 'store/wallet';
21import { useWallet } from 'store/wallet';
21import usePermissionsForPoint from 'lib/usePermissionsForPoint';
22import usePermissionsForPoint from 'lib/usePermissionsForPoint';
22
23
24+const isPlanet = point =>
25+ azimuth.getPointSize(point) === azimuth.PointSize.Planet;
26+
23export default function Point() {
27export default function Point() {
24 const history = useHistory();
28 const history = useHistory();
25 const { pointCursor } = usePointCursor();
29 const { pointCursor } = usePointCursor();
@@ -27,7 +31,7 @@ export default function Point() {
27
31
28 const point = need.point(pointCursor);
32 const point = need.point(pointCursor);
29
33
30− const { canManage } = usePermissionsForPoint(
34+ const { isOwner, canManage } = usePermissionsForPoint(
31 // using empty string should be ok here
35 // using empty string should be ok here
32 wallet.matchWith({
36 wallet.matchWith({
33 Nothing: () => '',
37 Nothing: () => '',
@@ -38,7 +42,6 @@ export default function Point() {
38
42
39 // fetch the invites for the current cursor
43 // fetch the invites for the current cursor
40 const { availableInvites } = useInvites(point);
44 const { availableInvites } = useInvites(point);
41− const availableInvitesText = matchBlinky(availableInvites);
42
45
43 const showActions = Just.hasInstance(wallet);
46 const showActions = Just.hasInstance(wallet);
44
47
@@ -48,6 +51,30 @@ export default function Point() {
48 history,
51 history,
49 ]);
52 ]);
50
53
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]);
77+
51 // sync the current cursor
78 // sync the current cursor
52 useSyncOwnedPoints([point]);
79 useSyncOwnedPoints([point]);
53
80
@@ -73,9 +100,7 @@ export default function Point() {
73 )}
100 )}
74 </Grid>
101 </Grid>
75
102
76− <FooterButton disabled={!canManage} onClick={goInvite}>
103+ {inviteButton}
77− Invite <sup>{availableInvitesText} available</sup>
78− </FooterButton>
79 </View>
104 </View>
80 );
105 );
81}
106}