import React, { useCallback, useState } from 'react'; import cn from 'classnames'; import { Just } from 'folktale/maybe'; import { Grid, Flex, Button } from 'indigo-react'; import { azimuth } from 'azimuth-js'; import { usePointCursor } from 'store/pointCursor'; import { useWallet } from 'store/wallet'; import View from 'components/View'; import Greeting from 'components/Greeting'; import Passport from 'components/Passport'; import Blinky, { matchBlinky } from 'components/Blinky'; import BarGraph from 'components/BarGraph'; import Chip from 'components/Chip'; import InviteSigilList from 'components/InviteSigilList'; import { ForwardButton } from 'components/Buttons'; import * as need from 'lib/need'; import useInvites from 'lib/useInvites'; import { useSyncExtras } from 'lib/useSyncPoints'; import useCurrentPermissions from 'lib/useCurrentPermissions'; import { useLocalRouter } from 'lib/LocalRouter'; import Inviter from 'views/Invite/Inviter'; import { usePointCache } from 'store/pointCache'; function InviteForm({ showInviteForm, setShowInviteForm, acceptedInvites, acceptedPoints, availableInvites, goCohort, pendingPoints, sentInvites, showInvites, }) { const _totalInvites = sentInvites.getOrElse(0) + availableInvites.getOrElse(0); const _pendingInvites = pendingPoints.getOrElse([]).length; return ( <> Invite Group View {acceptedInvites.getOrElse(0)} / {_totalInvites} {_pendingInvites > 0 && ( {_pendingInvites} pending )} {showInvites && ( <> > )} {!showInvites && ( <> Start your invite group by adding members > )} {!showInviteForm && availableInvites.getOrElse(0) > 0 && ( setShowInviteForm(true)}> Add Members )} {showInviteForm && } > ); } export default function Point() { const { pop, push, names } = useLocalRouter(); const { pointCursor } = usePointCursor(); const { wallet, urbitWallet } = useWallet(); const point = need.point(pointCursor); const { getResidents } = usePointCache(); const { residentCount, requestCount } = getResidents(point); const { isParent, isActiveOwner, canManage, canSpawn, canVote, } = useCurrentPermissions(); const canBitcoin = Just.hasInstance(urbitWallet); // fetch the invites for the current cursor const invites = useInvites(point); const { availableInvites, sentInvites, acceptedInvites, pendingPoints, acceptedPoints, } = invites; const showInvites = !( acceptedInvites.getOrElse(0) === 0 && sentInvites.getOrElse(0) === 0 ); const hasInvites = showInvites || availableInvites.getOrElse(0) !== 0; const loadedInvites = Just.hasInstance(availableInvites); // // availableInvites.getOrElse(0) === 0 const goSenate = useCallback(() => push(names.SENATE), [push, names]); const goCohort = useCallback(() => push(names.INVITE_COHORT), [push, names]); const goUrbitOS = useCallback(() => push(names.URBIT_OS), [push, names]); const goBitcoin = useCallback(() => push(names.BITCOIN), [push, names]); const goUrbitID = useCallback(() => push(names.URBIT_ID), [push, names]); const goResidents = useCallback(() => push(names.RESIDENTS), [push, names]); const goPartiesSetPoolSize = useCallback( () => push(names.PARTY_SET_POOL_SIZE), [push, names] ); const goIssuePoint = useCallback(() => push(names.ISSUE_CHILD), [ names.ISSUE_CHILD, push, ]); const isPlanet = azimuth.getPointSize(point) === azimuth.PointSize.Planet; const [showInviteForm, setShowInviteForm] = useState(false); const inviteButton = (() => { if (azimuth.getPointSize(point) === azimuth.PointSize.Star) { return ( <> Manage Invite Pools > ); } return null; })(); const senateButton = (() => { if (azimuth.getPointSize(point) !== azimuth.PointSize.Galaxy) { return null; } return ( <> Senate > ); })(); // sync the current cursor useSyncExtras([point]); const address = need.addressFromWallet(wallet); const _requestCount = requestCount.getOrElse(0); return ( {isParent && ( Residents{' '} {matchBlinky(residentCount)} {_requestCount !== 0 && ( {_requestCount} PENDING )} )} {isPlanet && hasInvites && ( )} {!loadedInvites && isPlanet && ( Invite Group )} {inviteButton} ID OS Bitcoin {isParent && ( <> Issue Point > )} {senateButton} ); }