Skip to content

Commit 0a45cae

Browse files
authored
Ng/connect fixes (#257)
1 parent fbb4204 commit 0a45cae

File tree

7 files changed

+185
-135
lines changed

7 files changed

+185
-135
lines changed

apps/connect/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"dependencies": {
1717
"@base-ui-components/react": "1.0.0-beta.0",
18+
"@graphprotocol/grc-20": "^0.21.2",
1819
"@graphprotocol/hypergraph": "workspace:*",
1920
"@graphprotocol/hypergraph-react": "workspace:*",
2021
"@privy-io/react-auth": "^2.13.0",

apps/connect/src/components/CreateSpaceCard.tsx

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Loading } from '@/components/ui/Loading';
22
import { cn } from '@/lib/utils';
3+
import { Graph } from '@graphprotocol/grc-20';
34
import { Key, type Messages, SpaceEvents, SpaceInfo, StoreConnect, Utils } from '@graphprotocol/hypergraph';
45
import { useIdentityToken } from '@privy-io/react-auth';
56
import { useQueryClient } from '@tanstack/react-query';
@@ -12,12 +13,36 @@ interface CreateSpaceCardProps extends Omit<React.HTMLAttributes<HTMLDivElement>
1213
export function CreateSpaceCard({ className, ...props }: CreateSpaceCardProps) {
1314
const [isLoading, setIsLoading] = useState(false);
1415
const [spaceName, setSpaceName] = useState('');
16+
const [spaceType, setSpaceType] = useState<'private' | 'public'>('private');
1517
const { identityToken } = useIdentityToken();
1618
const accountAddress = useSelector(StoreConnect.store, (state) => state.context.accountAddress);
1719
const keys = useSelector(StoreConnect.store, (state) => state.context.keys);
1820
const queryClient = useQueryClient();
1921

20-
const createSpace = async () => {
22+
const createPublicSpace = async () => {
23+
if (!accountAddress) {
24+
alert('Missing account address');
25+
return;
26+
}
27+
28+
setIsLoading(true);
29+
30+
try {
31+
await Graph.createSpace({
32+
editorAddress: accountAddress,
33+
name: spaceName,
34+
network: 'TESTNET',
35+
});
36+
} catch (error) {
37+
alert('Failed to create space');
38+
console.error(error);
39+
} finally {
40+
setIsLoading(false);
41+
queryClient.invalidateQueries({ queryKey: ['public-spaces'] });
42+
}
43+
};
44+
45+
const createPrivateSpace = async () => {
2146
setIsLoading(true);
2247
if (!accountAddress || !keys || !identityToken) {
2348
console.error('Missing required fields', {
@@ -84,7 +109,7 @@ export function CreateSpaceCard({ className, ...props }: CreateSpaceCardProps) {
84109
});
85110
const data = await response.json();
86111
if (data.space) {
87-
queryClient.invalidateQueries({ queryKey: ['spaces'] });
112+
queryClient.invalidateQueries({ queryKey: ['private-spaces'] });
88113
setSpaceName('');
89114
} else {
90115
throw new Error('Failed to create space');
@@ -97,10 +122,24 @@ export function CreateSpaceCard({ className, ...props }: CreateSpaceCardProps) {
97122
}
98123
};
99124

125+
const createSpace = async () => {
126+
if (spaceType === 'private') {
127+
await createPrivateSpace();
128+
} else {
129+
await createPublicSpace();
130+
}
131+
};
132+
100133
return (
101134
<div className={cn('c-card', className)} {...props}>
102135
<h2 className="c-card-title">Create a new space</h2>
103-
<form className="flex gap-2">
136+
<form
137+
className="flex gap-2"
138+
onSubmit={(event) => {
139+
event.preventDefault();
140+
createSpace();
141+
}}
142+
>
104143
<input
105144
type="text"
106145
placeholder="My cool space"
@@ -109,7 +148,15 @@ export function CreateSpaceCard({ className, ...props }: CreateSpaceCardProps) {
109148
required
110149
className="c-input grow"
111150
/>
112-
<button type="submit" disabled={isLoading} onClick={createSpace} className="c-button shrink-0">
151+
<select
152+
className="c-input min-w-22"
153+
value={spaceType}
154+
onChange={(e) => setSpaceType(e.target.value as 'private' | 'public')}
155+
>
156+
<option value="private">Private</option>
157+
<option value="public">Public</option>
158+
</select>
159+
<button type="submit" disabled={isLoading} className="c-button shrink-0">
113160
Create Space
114161
{isLoading ? <Loading hideLabel /> : null}
115162
</button>

apps/connect/src/routes/authenticate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ function AuthenticateComponent() {
575575
<CreateSpaceCard className="lg:col-2" />
576576
<div className="relative min-h-80 lg:col-2">
577577
<SpacesCard
578-
spaces={privateSpacesData ?? []}
578+
spaces={[...(privateSpacesData ?? []), ...(publicSpacesData ?? [])]}
579579
status={
580580
privateSpacesPending
581581
? 'loading'

apps/events/src/components/create-properties-and-types-event.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ export const CreatePropertiesAndTypesEvent = ({ space }: { space: string }) => {
102102
name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'),
103103
},
104104
relations: {
105-
sponsors: Id.Id('${sponsorsRelationTypeId}'),
105+
sponsors: Id.Id('${sponsorsRelationTypeId}'),
106106
},
107107
},
108108
Company: {
109109
typeIds: [Id.Id('${companyTypeId}')],
110110
properties: {
111111
name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'),
112+
},
113+
relations: {
112114
jobOffers: Id.Id('${jobOffersRelationTypeId}'),
113115
},
114116
},

apps/events/src/mapping.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,31 @@ import type { Mapping } from '@graphprotocol/hypergraph';
33

44
export const mapping: Mapping = {
55
Event: {
6-
typeIds: [Id.Id('6b8dbe76-389f-4bde-acdd-db9d5e387882')],
6+
typeIds: [Id.Id('407d9e8a-c703-4fb4-830d-98c758c8564e')],
77
properties: {
88
name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'),
99
},
1010
relations: {
11-
sponsors: Id.Id('d8e4ea54-cb8c-4dca-9c2b-64dbbbe78397'),
11+
sponsors: Id.Id('a7ac80a6-d3d9-4b04-9b9f-ead1723af09f'),
1212
},
1313
},
1414
Company: {
15-
typeIds: [Id.Id('e8932986-67a9-4fff-89a6-07f03973014c')],
15+
typeIds: [Id.Id('b0220a78-9205-4e5e-9bf1-c03ee0791e23')],
1616
properties: {
1717
name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'),
1818
},
1919
relations: {
20-
jobOffers: Id.Id('96beadca-0846-4e56-9628-c196f7f3c4cd'),
20+
jobOffers: Id.Id('7ca8063c-3664-479b-912d-1b3b86af2bf4'),
2121
},
2222
},
2323
JobOffer: {
24-
typeIds: [Id.Id('a107c081-3089-4a94-8208-6a10775557d2')],
24+
typeIds: [Id.Id('99e1733b-661d-4edb-a253-98ff4b7747d0')],
2525
properties: {
2626
name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'),
27-
salary: Id.Id('20d18713-5352-4e1f-987c-d853bf9f8831'),
27+
salary: Id.Id('5ecfb4e5-09eb-437d-9c3c-e9e7395d52aa'),
2828
},
2929
},
30+
3031
// Todo2: {
3132
// typeIds: [Id.Id('LJuM8ju67mCv78FhAiK9k9')],
3233
// properties: {

apps/events/src/routes/playground.lazy.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ export const Route = createLazyFileRoute('/playground')({
1010

1111
function RouteComponent() {
1212
return (
13-
<HypergraphSpaceProvider space="1c954768-7e14-4f0f-9396-0fe9dcd55fe8">
13+
<HypergraphSpaceProvider space="d9814a82-8dab-4d02-86d2-9d413f7dc336">
1414
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
1515
<h1 className="text-2xl font-bold">Playground</h1>
1616
<Playground />
17-
<CreatePropertiesAndTypesEvent space="1c954768-7e14-4f0f-9396-0fe9dcd55fe8" />
18-
<CreateEvents space="1c954768-7e14-4f0f-9396-0fe9dcd55fe8" />
17+
<CreatePropertiesAndTypesEvent space="d9814a82-8dab-4d02-86d2-9d413f7dc336" />
18+
<CreateEvents space="d9814a82-8dab-4d02-86d2-9d413f7dc336" />
1919
</div>
2020
</HypergraphSpaceProvider>
2121
);

0 commit comments

Comments
 (0)