Skip to content

Commit 0dd7abe

Browse files
authored
connect improvements (#226)
1 parent 45cefef commit 0dd7abe

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

apps/connect/src/components/spaces.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ import { useSpaces } from '@/hooks/use-spaces';
33
export function Spaces() {
44
const { isPending, error, data } = useSpaces();
55

6-
if (isPending) return 'Loading spaces …';
7-
8-
if (error) return `An error has occurred: ${error.message}`;
9-
106
return (
117
<div>
128
<h2 className="font-bold mb-2 mt-2">Spaces</h2>
139
<ul className="space-y-4">
14-
{data.map((space) => (
10+
{!isPending && !error && data && data.length === 0 && <p>No spaces found</p>}
11+
{isPending && <p>Loading spaces …</p>}
12+
{error && <p>An error has occurred loading spaces: {error.message}</p>}
13+
{data?.map((space) => (
1514
<li key={space.id}>
1615
<p>{space.name}</p>
1716
<p className="text-xs text-gray-500 mt-2 mb-1">Apps with access to this space</p>

apps/connect/src/routes/__root.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export const Route = createRootRoute({
1414
}
1515

1616
if (ready && !authenticated) {
17+
if (router.state.location.href.startsWith('/authenticate')) {
18+
localStorage.setItem('geo-connect-authenticate-redirect', router.state.location.href);
19+
}
1720
router.navigate({
1821
to: '/login',
1922
});

apps/connect/src/routes/authenticate.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,7 @@ function AuthenticateComponent() {
135135

136136
const state = useSelector(componentStore, (state) => state.context);
137137

138-
const {
139-
// isPending,
140-
// error,
141-
data: spacesData,
142-
} = useSpaces();
138+
const { isPending, error: spacesError, data: spacesData } = useSpaces();
143139

144140
useEffect(() => {
145141
const run = async () => {
@@ -452,6 +448,9 @@ function AuthenticateComponent() {
452448
</div>
453449
<h2 className="font-bold mb-2 mt-2">Spaces</h2>
454450
<ul className="space-y-4">
451+
{isPending && <p>Loading spaces …</p>}
452+
{spacesError && <p>An error has occurred loading spaces: {spacesError.message}</p>}
453+
{!isPending && !spacesError && spacesData?.length === 0 && <p>No spaces found</p>}
455454
{spacesData?.map((space) => (
456455
<li key={space.id}>
457456
<p>{space.name}</p>

apps/connect/src/routes/login.lazy.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ function Login() {
6868
};
6969

7070
await hypergraphLogin(signer);
71-
navigate({ to: '/' });
71+
72+
const redirect = localStorage.getItem('geo-connect-authenticate-redirect');
73+
if (redirect) {
74+
localStorage.removeItem('geo-connect-authenticate-redirect');
75+
navigate({ to: redirect, replace: true });
76+
return;
77+
}
78+
79+
navigate({ to: '/', replace: true });
7280
} catch (error) {
7381
alert('Failed to login');
7482
console.error(error);

0 commit comments

Comments
 (0)