on ebac710 help sign in
bridge/src/views/Point.js
306 lines 8.1 kB history raw
1import React, { useCallback, useState } from 'react';
2import cn from 'classnames';
3import { Just } from 'folktale/maybe';
4import { Grid, Flex, Button } from 'indigo-react';
5import { azimuth } from 'azimuth-js';
7import { usePointCursor } from 'store/pointCursor';
8import { useWallet } from 'store/wallet';
10import View from 'components/View';
11import Greeting from 'components/Greeting';
12import Passport from 'components/Passport';
13import Blinky, { matchBlinky } from 'components/Blinky';
14import BarGraph from 'components/BarGraph';
15import Chip from 'components/Chip';
16import InviteSigilList from 'components/InviteSigilList';
17import { ForwardButton } from 'components/Buttons';
19import * as need from 'lib/need';
20import useInvites from 'lib/useInvites';
21import { useSyncOwnedPoints } from 'lib/useSyncPoints';
22import useCurrentPermissions from 'lib/useCurrentPermissions';
23import { useLocalRouter } from 'lib/LocalRouter';
25import Inviter from 'views/Invite/Inviter';
26import { usePointCache } from 'store/pointCache';
28function InviteForm({
29 showInviteForm,
30 setShowInviteForm,
31 acceptedInvites,
32 acceptedPoints,
33 availableInvites,
34 goCohort,
35 pendingPoints,
36 sentInvites,
37 showInvites,
38}) {
39 const _totalInvites =
40 sentInvites.getOrElse(0) + availableInvites.getOrElse(0);
41 const _pendingInvites = pendingPoints.getOrElse([]).length;
43 return (
44 <>
45 <Grid.Item cols={[1, 11]}>
46 Invite Group
47 <br />
48 </Grid.Item>
50 <Grid.Item
51 className={cn('t-right underline pointer-hover', {
52 gray4: sentInvites.getOrElse(0) === 0,
53 })}
54 onClick={goCohort}
55 cols={[11, 13]}>
56 View
57 </Grid.Item>
58 <Grid.Item full>
59 <Flex align="center">
60 <Flex.Item>
61 {acceptedInvites.getOrElse(0)} / {_totalInvites}
62 </Flex.Item>
63 {_pendingInvites > 0 && (
64 <Flex.Item as={Chip} className="bg-yellow1 yellow4">
65 {_pendingInvites} pending
66 </Flex.Item>
67 )}
68 </Flex>
69 </Grid.Item>
71 {showInvites && (
72 <>
73 <Grid.Item
74 full
75 as={BarGraph}
76 available={availableInvites}
77 sent={sentInvites}
78 accepted={acceptedInvites}
79 />
80 <Grid.Item
81 full
82 as={InviteSigilList}
83 pendingPoints={pendingPoints}
84 acceptedPoints={acceptedPoints}
85 />
86 </>
87 )}
88 {!showInvites && (
89 <>
90 <Grid.Item full className="b-gray4 b-dotted b1 self-center">
91 <div className="p4 pv8 t-center gray4">
92 Start your invite group by adding members
93 </div>
94 </Grid.Item>
95 </>
96 )}
97 {!showInviteForm && availableInvites.getOrElse(0) > 0 && (
98 <Grid.Item
99 full
100 solid
101 as={Button}
102 center
103 onClick={() => setShowInviteForm(true)}>
104 Add Members
105 </Grid.Item>
106 )}
107 {showInviteForm && <Inviter />}
108 <Grid.Item full className="mb2" />
109 </>
110 );
113export default function Point() {
114 const { pop, push, names } = useLocalRouter();
115 const { pointCursor } = usePointCursor();
117 const { wallet } = useWallet();
118 const point = need.point(pointCursor);
120 const { getResidents } = usePointCache();
122 const { residentCount, requestCount } = getResidents(point);
124 const {
125 isParent,
126 isActiveOwner,
127 canManage,
128 canSpawn,
129 canVote,
130 isOwner,
131 } = useCurrentPermissions();
133 // fetch the invites for the current cursor
134 const invites = useInvites(point);
135 const {
136 availableInvites,
137 sentInvites,
138 acceptedInvites,
139 pendingPoints,
140 acceptedPoints,
141 } = invites;
143 const showInvites = !(
144 acceptedInvites.getOrElse(0) === 0 && sentInvites.getOrElse(0) === 0
145 );
147 const hasInvites = showInvites || availableInvites.getOrElse(0) !== 0;
149 const loadedInvites = Just.hasInstance(availableInvites);
150 //
151 // availableInvites.getOrElse(0) === 0
153 const goSenate = useCallback(() => push(names.SENATE), [push, names]);
155 const goCohort = useCallback(() => push(names.INVITE_COHORT), [push, names]);
157 const goUrbitOS = useCallback(() => push(names.URBIT_OS), [push, names]);
159 const goUrbitID = useCallback(() => push(names.URBIT_ID), [push, names]);
161 const goResidents = useCallback(() => push(names.RESIDENTS), [push, names]);
163 const goPartiesSetPoolSize = useCallback(
164 () => push(names.PARTY_SET_POOL_SIZE),
165 [push, names]
166 );
168 const goIssuePoint = useCallback(() => push(names.ISSUE_CHILD), [
169 names.ISSUE_CHILD,
170 push,
171 ]);
173 const isPlanet = azimuth.getPointSize(point) === azimuth.PointSize.Planet;
175 const [showInviteForm, setShowInviteForm] = useState(false);
177 const inviteButton = (() => {
178 if (azimuth.getPointSize(point) === azimuth.PointSize.Star) {
179 return (
180 <>
181 <Grid.Item
182 full
183 as={ForwardButton}
184 disabled={!isActiveOwner}
185 onClick={goPartiesSetPoolSize}>
186 Manage Invite Pools
187 </Grid.Item>
188 <Grid.Divider />
189 </>
190 );
191 }
193 return null;
194 })();
196 const senateButton = (() => {
197 if (azimuth.getPointSize(point) !== azimuth.PointSize.Galaxy) {
198 return null;
199 }
200 return (
201 <>
202 <Grid.Item
203 full
204 as={ForwardButton}
205 disabled={!canVote}
206 onClick={goSenate}>
207 Senate
208 </Grid.Item>
209 <Grid.Divider />
210 </>
211 );
212 })();
214 // sync the current cursor
215 useSyncOwnedPoints([point]);
217 const address = need.addressFromWallet(wallet);
219 const _requestCount = requestCount.getOrElse(0);
221 return (
222 <View pop={pop} inset>
223 <Greeting point={point} />
224 <Passport
225 point={Just(point)}
226 address={Just(address)}
227 animationMode={'slide'}
228 />
229 <Grid gap={3}>
230 {isParent && (
231 <Grid.Item
232 full
233 as={Flex}
234 justify="between"
235 onClick={goResidents}
236 className="mv1 pointer">
237 <Flex.Item>
238 Residents{' '}
239 <span className="gray3">{matchBlinky(residentCount)}</span>
240 </Flex.Item>
241 {_requestCount !== 0 && (
242 <Flex.Item className="f7 bg-gray2 h3 pv1 ph2 br-full r-full text-center">
243 {_requestCount} PENDING
244 </Flex.Item>
245 )}
246 </Grid.Item>
247 )}
248 {isPlanet && hasInvites && (
249 <InviteForm
250 showInviteForm={showInviteForm}
251 setShowInviteForm={setShowInviteForm}
252 acceptedInvites={acceptedInvites}
253 acceptedPoints={acceptedPoints}
254 availableInvites={availableInvites}
255 goCohort={goCohort}
256 pendingPoints={pendingPoints}
257 sentInvites={sentInvites}
258 showInvites={showInvites}
259 />
260 )}
261 {!loadedInvites && isPlanet && (
262 <Grid.Item className="mv2" full>
263 Invite Group <Blinky />
264 </Grid.Item>
265 )}
266 </Grid>
267 <Grid className="pt2">
268 <Grid.Divider />
269 {inviteButton}
270 <Grid.Item
271 full
272 as={ForwardButton}
273 disabled={!canManage}
274 onClick={goUrbitID}
275 className="mt1"
276 detail="Identity and security settings">
277 ID
278 </Grid.Item>
279 <Grid.Divider />
280 <Grid.Item
281 full
282 as={ForwardButton}
283 disabled={!canManage}
284 className="mt1"
285 detail="Urbit OS Settings"
286 onClick={goUrbitOS}>
287 OS
288 </Grid.Item>
289 <Grid.Divider />
290 {isParent && (
291 <>
292 <Grid.Item
293 full
294 as={ForwardButton}
295 disabled={!canSpawn}
296 onClick={goIssuePoint}>
297 Issue Point
298 </Grid.Item>
299 <Grid.Divider />
300 </>
301 )}
302 {senateButton}
303 </Grid>
304 </View>
305 );