import React, { useCallback, useState } from 'react'; import cn from 'classnames'; import { Just } from 'folktale/maybe'; import { Grid, Flex } 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 { ForwardButton, BootUrbitOSButton } from 'components/Buttons'; import CopyButton from 'components/CopyButton'; import { matchBlinky } from 'components/Blinky'; import DownloadSigilButton from 'components/DownloadSigilButton'; import BarGraph from 'components/BarGraph'; import Chip from 'components/Chip'; import InviteSigilList from 'components/InviteSigilList'; import * as need from 'lib/need'; import useInvites from 'lib/useInvites'; import { useSyncOwnedPoints } from 'lib/useSyncPoints'; import useCurrentPermissions from 'lib/useCurrentPermissions'; import { useLocalRouter } from 'lib/LocalRouter'; import useKeyfileGenerator from 'lib/useKeyfileGenerator'; import InviteCohort from 'views/Invite/Cohort'; export default function Point() { const { pop, push, names } = useLocalRouter(); const { pointCursor } = usePointCursor(); const { wallet } = useWallet(); const point = need.point(pointCursor); const { code, notice } = useKeyfileGenerator(); const { isParent, isActiveOwner, canManage, canSpawn, canVote, } = useCurrentPermissions(); // 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 _totalInvites = sentInvites.getOrElse(0) + availableInvites.getOrElse(0); const _pendingInvites = pendingPoints.getOrElse([]).length; // // availableInvites.getOrElse(0) === 0 const goAdmin = useCallback(() => push(names.ADMIN), [push, names]); const goSenate = useCallback(() => push(names.SENATE), [push, names]); const goInvite = useCallback(() => push(names.INVITE), [push, names]); const goParty = useCallback(() => push(names.PARTY), [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 = (() => { switch (azimuth.getPointSize(point)) { case azimuth.PointSize.Planet: const availableInvitesText = matchBlinky(availableInvites); return ( <> Invite {availableInvitesText} ); // case azimuth.PointSize.Star: return ( <> Manage Invite Pools ); // default: return null; } })(); const senateButton = (() => { if (azimuth.getPointSize(point) !== azimuth.PointSize.Galaxy) { return null; } return ( <> Senate ); })(); // sync the current cursor useSyncOwnedPoints([point]); const address = need.addressFromWallet(wallet); return ( {isPlanet && hasInvites && ( <> Invite Group
View {acceptedInvites.getOrElse(0) + _pendingInvites} /{' '} {_totalInvites} {_pendingInvites > 0 && ( {_pendingInvites} pending )} {showInvites && ( <> )} {!showInvites && ( <>
Start your invite group by adding members
)} {!showInviteForm && availableInvites.getOrElse(0) > 0 && ( setShowInviteForm(true)}> Add Members )} {showInviteForm && } )}
{inviteButton} Admin {isParent && ( <> Issue Point )} {senateButton} } detail={code || notice} disabled={!code} detailClassName="mono"> Login Code
); }