Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions apps/events/src/components/create-events.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getSmartAccountWalletClient } from '@/lib/smart-account';
import { type GeoSmartAccount, Graph, type Op } from '@graphprotocol/grc-20';
import { publishOps, useHypergraphSpace } from '@graphprotocol/hypergraph-react';
import { publishOps } from '@graphprotocol/hypergraph-react';
import { Button } from './ui/button';

const createEvents = async ({
Expand Down Expand Up @@ -69,9 +69,7 @@ const createEvents = async ({
}
};

export const CreateEvents = () => {
const space = useHypergraphSpace();

export const CreateEvents = ({ space }: { space: string }) => {
return (
<div>
<Button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getSmartAccountWalletClient } from '@/lib/smart-account';
import { type GeoSmartAccount, Graph, type Op } from '@graphprotocol/grc-20';
import { publishOps, useHypergraphSpace } from '@graphprotocol/hypergraph-react';
import { publishOps } from '@graphprotocol/hypergraph-react';
import { useState } from 'react';
import { Button } from './ui/button';
import { Card, CardContent } from './ui/card';
Expand Down Expand Up @@ -66,9 +66,8 @@ const createPropertiesAndTypesEvent = async ({
};
};

export const CreatePropertiesAndTypesEvent = () => {
export const CreatePropertiesAndTypesEvent = ({ space }: { space: string }) => {
const [mapping, setMapping] = useState<string>('');
const space = useHypergraphSpace();

return (
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getSmartAccountWalletClient } from '@/lib/smart-account';
import { type GeoSmartAccount, Graph, type Op } from '@graphprotocol/grc-20';
import { publishOps, useHypergraphSpace } from '@graphprotocol/hypergraph-react';
import { publishOps } from '@graphprotocol/hypergraph-react';
import { useState } from 'react';
import { Button } from './ui/button';
import { Card, CardContent } from './ui/card';
Expand Down Expand Up @@ -70,6 +70,7 @@ const createPropertiesAndTypesTodos = async ({
walletClient: smartAccountWalletClient,
space,
name: 'Create properties and types',
network: 'TESTNET',
});
return {
result,
Expand All @@ -84,9 +85,8 @@ const createPropertiesAndTypesTodos = async ({
};
};

export const CreatePropertiesAndTypesTodos = () => {
export const CreatePropertiesAndTypesTodos = ({ space }: { space: string }) => {
const [mapping, setMapping] = useState<string>('');
const space = useHypergraphSpace();

return (
<div>
Expand All @@ -113,6 +113,7 @@ export const CreatePropertiesAndTypesTodos = () => {
websitePropertyId,
amountPropertyId,
} = await createPropertiesAndTypesTodos({
// @ts-expect-error - TODO: fix the types error
smartAccountWalletClient,
space,
});
Expand Down
11 changes: 1 addition & 10 deletions apps/events/src/components/dev-tool.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { store } from '@graphprotocol/hypergraph';
import { useHypergraphApp } from '@graphprotocol/hypergraph-react';
import { useSelector } from '@xstate/store/react';
import { useEffect, useState } from 'react';
import { useState } from 'react';

import { Button } from './ui/button';

Expand All @@ -10,13 +9,6 @@ export function DevTool({ spaceId }: { spaceId: string }) {

const spaces = useSelector(store, (state) => state.context.spaces);
const updatesInFlight = useSelector(store, (state) => state.context.updatesInFlight);
const { subscribeToSpace, isConnecting } = useHypergraphApp();

useEffect(() => {
if (!isConnecting) {
subscribeToSpace({ spaceId });
}
}, [isConnecting, subscribeToSpace, spaceId]);

const space = spaces.find((space) => space.id === spaceId);

Expand All @@ -39,7 +31,6 @@ export function DevTool({ spaceId }: { spaceId: string }) {
<p>Keys:</p>
<pre className="text-xs">{JSON.stringify(space.keys)}</pre>
<br />
<h3>Last update clock: {space.lastUpdateClock}</h3>
<h3>Updates in flight</h3>
<ul className="text-xs">
{updatesInFlight.map((updateInFlight) => {
Expand Down
18 changes: 7 additions & 11 deletions apps/events/src/components/todo/todos-public.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { getSmartAccountWalletClient } from '@/lib/smart-account';
import { Id } from '@graphprotocol/grc-20';
import {
_generateDeleteOps,
publishOps,
useCreateEntity,
useHypergraphSpace,
useQuery,
} from '@graphprotocol/hypergraph-react';
import { _generateDeleteOps, publishOps, useCreateEntity, useQuery, useSpace } from '@graphprotocol/hypergraph-react';
import { useGenerateCreateOps } from '@graphprotocol/hypergraph-react/internal/use-generate-create-ops';
import { Todo2 } from '../../schema';
import { Spinner } from '../spinner';
import { Button } from '../ui/button';

export const TodosPublic = () => {
const space = useHypergraphSpace();
const { id: spaceId } = useSpace({ mode: 'public' });
const {
data: dataPublic,
isLoading: isLoadingPublic,
Expand Down Expand Up @@ -54,11 +48,12 @@ export const TodosPublic = () => {
if (!smartAccountWalletClient) {
throw new Error('Missing smartAccountWalletClient');
}
const ops = await _generateDeleteOps({ id: todo.id, space });
const ops = await _generateDeleteOps({ id: todo.id, space: spaceId });
const result = await publishOps({
ops,
// @ts-expect-error - TODO: fix the types error
walletClient: smartAccountWalletClient,
space,
space: spaceId,
name: 'Delete Todo',
});
console.log('result', result);
Expand Down Expand Up @@ -89,8 +84,9 @@ export const TodosPublic = () => {
console.log('ops', ops);
const result = await publishOps({
ops,
// @ts-expect-error - TODO: fix the types error
walletClient: smartAccountWalletClient,
space,
space: spaceId,
name: 'Create Todo',
});
console.log('result', result);
Expand Down
6 changes: 6 additions & 0 deletions apps/events/src/components/todos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
useDeleteEntity,
useQuery,
useRemoveRelation,
useSpace,
useUpdateEntity,
} from '@graphprotocol/hypergraph-react';
import { useEffect, useState } from 'react';
Expand All @@ -14,6 +15,7 @@ import { Input } from './ui/input';
export const Todos = () => {
const { data: todos } = useQuery(Todo, { mode: 'private', include: { assignees: {} } });
const { data: users } = useQuery(User, { mode: 'private' });
const { ready: spaceReady } = useSpace({ mode: 'private' });
const createEntity = useCreateEntity(Todo);
const updateEntity = useUpdateEntity(Todo);
const deleteEntity = useDeleteEntity();
Expand All @@ -28,6 +30,10 @@ export const Todos = () => {
});
}, [users]);

if (!spaceReady) {
return <div>Loading space...</div>;
}

const userOptions = users.map((user) => ({ value: user.id, label: user.name }));
return (
<>
Expand Down
10 changes: 7 additions & 3 deletions apps/events/src/components/todos2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
publishOps,
useCreateEntity,
useDeleteEntity,
useHypergraphSpace,
useQuery,
useSpace,
useUpdateEntity,
} from '@graphprotocol/hypergraph-react';
import { useQueryClient } from '@tanstack/react-query';
Expand All @@ -34,7 +34,7 @@ export const Todos2 = () => {
isError: isErrorUsers,
// preparePublish: preparePublishUsers,
} = useQuery(User, { mode: 'private' });
const space = useHypergraphSpace();
const { ready: spaceReady, id: spaceId } = useSpace({ mode: 'private' });
const createTodo = useCreateEntity(Todo2);
const updateTodo = useUpdateEntity(Todo2);
const createUser = useCreateEntity(User);
Expand All @@ -57,6 +57,10 @@ export const Todos2 = () => {

const userOptions = dataUsers.map((user) => ({ value: user.id, label: user.name }));

if (!spaceReady) {
return <div>Loading space...</div>;
}

return (
<>
<div className="flex flex-row gap-4 items-center">
Expand Down Expand Up @@ -231,7 +235,7 @@ export const Todos2 = () => {
ops,
// @ts-expect-error - TODO: fix the types error
walletClient: smartAccountWalletClient,
space,
space: spaceId,
name: 'Update users and todos',
});
console.log('publishOpsResult', publishOpsResult);
Expand Down
9 changes: 7 additions & 2 deletions apps/events/src/components/users.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCreateEntity, useQuery } from '@graphprotocol/hypergraph-react';
import { useCreateEntity, useQuery, useSpace } from '@graphprotocol/hypergraph-react';
import { useState } from 'react';
import { User } from '../schema.js';
import { Button } from './ui/button.js';
Expand All @@ -7,9 +7,14 @@ import { UserEntry } from './user-entry.js';

export const Users = () => {
const { data: users } = useQuery(User, { mode: 'private' });
const createEntity = useCreateEntity(User);
const { ready: spaceReady } = useSpace({ mode: 'private' });
const createEntity = useCreateEntity(User, { space: '1c954768-7e14-4f0f-9396-0fe9dcd55fe8' });
const [newUserName, setNewUserName] = useState('');

if (!spaceReady) {
return <div>Loading space...</div>;
}

return (
<>
<h1 className="text-2xl font-bold">Users</h1>
Expand Down
9 changes: 5 additions & 4 deletions apps/events/src/components/users/users-public.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getSmartAccountWalletClient } from '@/lib/smart-account';
import { _generateDeleteOps, publishOps, useHypergraphSpace, useQuery } from '@graphprotocol/hypergraph-react';
import { _generateDeleteOps, publishOps, useQuery, useSpace } from '@graphprotocol/hypergraph-react';
import { User } from '../../schema';
import { Spinner } from '../spinner';
import { Button } from '../ui/button';

export const UsersPublic = () => {
const space = useHypergraphSpace();
const { id: spaceId } = useSpace({ mode: 'public' });
const { data: dataPublic, isLoading: isLoadingPublic, isError: isErrorPublic } = useQuery(User, { mode: 'public' });

return (
Expand All @@ -26,11 +26,12 @@ export const UsersPublic = () => {
if (!smartAccountWalletClient) {
throw new Error('Missing smartAccountWalletClient');
}
const ops = await _generateDeleteOps({ id: user.id, space });
const ops = await _generateDeleteOps({ id: user.id, space: spaceId });
const result = await publishOps({
ops,
// @ts-expect-error - TODO: fix the types error
walletClient: smartAccountWalletClient,
space,
space: spaceId,
name: 'Delete User',
});
console.log('result', result);
Expand Down
4 changes: 2 additions & 2 deletions apps/events/src/routes/playground.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function RouteComponent() {
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
<h1 className="text-2xl font-bold">Playground</h1>
<Playground />
<CreatePropertiesAndTypesEvent />
<CreateEvents />
<CreatePropertiesAndTypesEvent space="1c954768-7e14-4f0f-9396-0fe9dcd55fe8" />
<CreateEvents space="1c954768-7e14-4f0f-9396-0fe9dcd55fe8" />
</div>
</HypergraphSpaceProvider>
);
Expand Down
23 changes: 3 additions & 20 deletions apps/events/src/routes/space/$spaceId/chat.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
import { SpaceChat } from '@/components/SpaceChat';
import { store } from '@graphprotocol/hypergraph';
import { HypergraphSpaceProvider, useHypergraphApp } from '@graphprotocol/hypergraph-react';
import { useHypergraphApp } from '@graphprotocol/hypergraph-react';
import { createFileRoute } from '@tanstack/react-router';
import { useSelector } from '@xstate/store/react';
import { useEffect } from 'react';

export const Route = createFileRoute('/space/$spaceId/chat')({
component: RouteComponent,
});

function RouteComponent() {
const { spaceId } = Route.useParams();
const spaces = useSelector(store, (state) => state.context.spaces);
const { subscribeToSpace, isConnecting } = useHypergraphApp();
useEffect(() => {
if (!isConnecting) {
subscribeToSpace({ spaceId });
}
}, [isConnecting, subscribeToSpace, spaceId]);

const space = spaces.find((space) => space.id === spaceId);
const { isConnecting } = useHypergraphApp();

if (isConnecting) {
return <div className="flex justify-center items-center h-screen">Loading …</div>;
}

if (!space) {
return <div className="flex justify-center items-center h-screen">Space not found</div>;
}

return (
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
<HypergraphSpaceProvider space={spaceId}>
<SpaceChat spaceId={spaceId} />
</HypergraphSpaceProvider>
<SpaceChat spaceId={spaceId} />
</div>
);
Comment on lines 18 to 21
Copy link

Copilot AI Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page no longer wraps its children in HypergraphSpaceProvider, so calling useSpace inside SpaceChat will throw. Please wrap the returned JSX in <HypergraphSpaceProvider space={spaceId}>.

Copilot uses AI. Check for mistakes.

}
18 changes: 2 additions & 16 deletions apps/events/src/routes/space/$spaceId/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,23 @@ import { TodosReadOnly } from '@/components/todos-read-only';
import { TodosReadOnlyFilter } from '@/components/todos-read-only-filter';
import { Button } from '@/components/ui/button';
import { Users } from '@/components/users';
import { store } from '@graphprotocol/hypergraph';
import { HypergraphSpaceProvider, useHypergraphApp } from '@graphprotocol/hypergraph-react';
import { createFileRoute } from '@tanstack/react-router';
import { useSelector } from '@xstate/store/react';
import { useEffect, useState } from 'react';
import { useState } from 'react';

export const Route = createFileRoute('/space/$spaceId/')({
component: Space,
});

function Space() {
const { spaceId } = Route.useParams();
const spaces = useSelector(store, (state) => state.context.spaces);
const { subscribeToSpace, isConnecting } = useHypergraphApp();
useEffect(() => {
if (!isConnecting) {
subscribeToSpace({ spaceId });
}
}, [isConnecting, subscribeToSpace, spaceId]);
const { isConnecting } = useHypergraphApp();
const [show2ndTodos, setShow2ndTodos] = useState(false);

const space = spaces.find((space) => space.id === spaceId);

if (isConnecting) {
return <div className="flex justify-center items-center h-screen">Loading …</div>;
}

if (!space) {
return <div className="flex justify-center items-center h-screen">Space not found</div>;
}

return (
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
<HypergraphSpaceProvider space={spaceId}>
Expand Down
17 changes: 1 addition & 16 deletions apps/events/src/routes/space/$spaceId/playground.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
import { TodosPublic } from '@/components/todo/todos-public';
import { store } from '@graphprotocol/hypergraph';
import { HypergraphSpaceProvider, useHypergraphApp } from '@graphprotocol/hypergraph-react';
import { createFileRoute } from '@tanstack/react-router';
import { useSelector } from '@xstate/store/react';
import { useEffect } from 'react';

export const Route = createFileRoute('/space/$spaceId/playground')({
component: PlaygroundRouteComponent,
});

function PlaygroundRouteComponent() {
const { spaceId } = Route.useParams();
const spaces = useSelector(store, (state) => state.context.spaces);
const { subscribeToSpace, isConnecting, isLoadingSpaces } = useHypergraphApp();
useEffect(() => {
if (!isConnecting) {
subscribeToSpace({ spaceId });
}
}, [isConnecting, subscribeToSpace, spaceId]);

const space = spaces.find((space) => space.id === spaceId);
const { isConnecting, isLoadingSpaces } = useHypergraphApp();

if (isConnecting || isLoadingSpaces[spaceId]) {
return <div className="flex justify-center items-center h-screen">Loading …</div>;
}

if (!space) {
return <div className="flex justify-center items-center h-screen">Space not found</div>;
}

return (
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
<HypergraphSpaceProvider space={spaceId}>
Expand Down
Loading
Loading