@@ -75,7 +75,7 @@ export default function InviteCohort() {
7575 const { contracts }: any = useNetwork();
7676 const { syncControlledPoints }: any = usePointCache();
7777
78− const point = Just(pointCursor)
78+ const point = pointCursor.getOrElse(null);
7979 const _contracts = need.contracts(contracts);
8080
8181 const [numInvites, setNumInvites] = useState(
@@ -83,13 +83,25 @@ export default function InviteCohort() {
8383 );
8484 const [showInviteForm, setShowInviteForm] = useState(false);
8585 const [loading, setLoading] = useState(false);
86− const [error, setError] = useState('');
8786 const [downloadingCsv, setDownloadingCsv] = useState(false);
87+ const [error, setError] = useState('');
8888 const [l1Invite, setL1Invite] = useState<L1Invite | null>(null);
8989 const [page, setPage] = useState(0);
9090
9191 const { construct, unconstruct, completed, bind } = useIssueChild();
9292
93+ const onClickShowInvite = useCallback(
94+ (planet: number) => {
95+ setLoading(true);
96+ // Put this in a timeout to let the UI update
97+ setTimeout(async () => {
98+ await showInvite(planet);
99+ setLoading(false);
100+ }, 50);
101+ },
102+ [setLoading, showInvite]
103+ );
104+
93105 useEffect(() => {
94106 if (invitePoints.length > 0) {
95107 getInvites(currentL2);
@@ -101,7 +113,7 @@ export default function InviteCohort() {
101113 const _authToken = authToken.getOrElse(null);
102114
103115 const setUpInvite = async () => {
104− setLoading(true);
116+ setDownloadingCsv(true);
105117 const possiblePoints = await azimuth.azimuth.getUnspawnedChildren(
106118 _contracts,
107119 point
@@ -132,7 +144,7 @@ export default function InviteCohort() {
132144 setError('No available planets');
133145 }
134146
135− setLoading(false);
147+ setDownloadingCsv(false);
136148 };
137149
138150 if (!currentL2 && _contracts && point && _authToken && showInviteForm) {
@@ -154,7 +166,12 @@ export default function InviteCohort() {
154166 useEffect(() => {
155167 const storedInvites = getStoredInvites(ls);
156168
157− if (!completed || !l1Invite || storedInvites[l1Invite.planet]) {
169+ if (
170+ !currentL2 ||
171+ !completed ||
172+ !l1Invite ||
173+ storedInvites[l1Invite.planet]
174+ ) {
158175 return;
159176 }
160177
@@ -164,7 +181,7 @@ export default function InviteCohort() {
164181 setL1Invite(null);
165182 unconstruct();
166183 pop();
167− }, [completed]); // eslint-disable-line react-hooks/exhaustive-deps
184+ }, [completed, currentL2]); // eslint-disable-line react-hooks/exhaustive-deps
168185
169186 const invitesToDisplay = invites.slice(
170187 page * INVITES_PER_PAGE,
@@ -198,7 +215,7 @@ export default function InviteCohort() {
198215
199216 const downloadCsv = useCallback(() => {
200217 const generateAndDownload = async () => {
201− setDownloadingCsv(true);
218+ setLoading(true);
202219 const invites = await getInvites(currentL2, true);
203220 if (invites) {
204221 const csv = invites.reduce(
@@ -218,14 +235,14 @@ export default function InviteCohort() {
218235 } else {
219236 setError('There was an error creating the CSV');
220237 }
221− setDownloadingCsv(false);
238+ setLoading(false);
222239 setInviteGeneratingNum(0);
223240 };
224241 generateAndDownload();
225242 }, [
226243 getInvites,
227244 setError,
228− setDownloadingCsv,
245+ setLoading,
229246 setInviteGeneratingNum,
230247 currentL2,
231248 point,
@@ -261,7 +278,7 @@ export default function InviteCohort() {
261278 ) : (
262279 <Button2
263280 className="secondary"
264− onClick={() => showInvite(invite.planet)}>
281+ onClick={() => onClickShowInvite(invite.planet)}>
265282 Show Invite
266283 </Button2>
267284 )}
@@ -437,7 +454,10 @@ export default function InviteCohort() {
437454 Add More
438455 </Button>
439456 )}
440− <LoadingOverlay loading={downloadingCsv} text={downloadingCsvText} />
457+ <LoadingOverlay
458+ loading={downloadingCsv || loading}
459+ text={downloadingCsv ? downloadingCsvText : undefined}
460+ />
441461 </View>
442462 );
443463}