Skip to content

Commit 9003282

Browse files
authored
move mapping to app provider (#233)
1 parent 8458747 commit 9003282

File tree

21 files changed

+189
-187
lines changed

21 files changed

+189
-187
lines changed

apps/events/src/Boot.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { HypergraphAppProvider } from '@graphprotocol/hypergraph-react';
22
import { RouterProvider, createRouter } from '@tanstack/react-router';
3+
import { mapping } from './mapping.js';
34
import { routeTree } from './routeTree.gen';
45

56
// Create a new router instance
@@ -14,7 +15,7 @@ declare module '@tanstack/react-router' {
1415

1516
export function Boot() {
1617
return (
17-
<HypergraphAppProvider storage={localStorage} syncServerUri="http://localhost:3030">
18+
<HypergraphAppProvider storage={localStorage} syncServerUri="http://localhost:3030" mapping={mapping}>
1819
<RouterProvider router={router} />
1920
</HypergraphAppProvider>
2021
);

apps/events/src/mapping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Id } from '@graphprotocol/grc-20';
2-
import type { Mapping } from '@graphprotocol/hypergraph-react';
2+
import type { Mapping } from '@graphprotocol/hypergraph';
33

44
export const mapping: Mapping = {
55
RelationEntry: {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Playground } from '@/components/playground';
2-
import { mapping } from '@/mapping.js';
32
import { HypergraphSpaceProvider } from '@graphprotocol/hypergraph-react';
43
import { createLazyFileRoute } from '@tanstack/react-router';
54

@@ -9,7 +8,7 @@ export const Route = createLazyFileRoute('/playground')({
98

109
function RouteComponent() {
1110
return (
12-
<HypergraphSpaceProvider space="93952dae-46e3-4682-b290-80028ca95403" mapping={mapping}>
11+
<HypergraphSpaceProvider space="93952dae-46e3-4682-b290-80028ca95403">
1312
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
1413
<h1 className="text-2xl font-bold">Playground</h1>
1514
<Playground />

apps/events/src/routes/space/$spaceId/chat.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { SpaceChat } from '@/components/SpaceChat';
2-
import { mapping } from '@/mapping.js';
32
import { store } from '@graphprotocol/hypergraph';
43
import { HypergraphSpaceProvider, useHypergraphApp } from '@graphprotocol/hypergraph-react';
54
import { createFileRoute } from '@tanstack/react-router';
@@ -32,7 +31,7 @@ function RouteComponent() {
3231

3332
return (
3433
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
35-
<HypergraphSpaceProvider space={spaceId} mapping={mapping}>
34+
<HypergraphSpaceProvider space={spaceId}>
3635
<SpaceChat spaceId={spaceId} />
3736
</HypergraphSpaceProvider>
3837
</div>

apps/events/src/routes/space/$spaceId/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { TodosReadOnly } from '@/components/todos-read-only';
44
import { TodosReadOnlyFilter } from '@/components/todos-read-only-filter';
55
import { Button } from '@/components/ui/button';
66
import { Users } from '@/components/users';
7-
import { mapping } from '@/mapping.js';
87
import { store } from '@graphprotocol/hypergraph';
98
import { HypergraphSpaceProvider, useHypergraphApp } from '@graphprotocol/hypergraph-react';
109
import { createFileRoute } from '@tanstack/react-router';
@@ -38,7 +37,7 @@ function Space() {
3837

3938
return (
4039
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
41-
<HypergraphSpaceProvider space={spaceId} mapping={mapping}>
40+
<HypergraphSpaceProvider space={spaceId}>
4241
<Users />
4342
<Todos />
4443
<TodosReadOnlyFilter />

apps/events/src/routes/space/$spaceId/playground.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { TodosPublic } from '@/components/todo/todos-public';
2-
import { mapping } from '@/mapping.js';
32
import { store } from '@graphprotocol/hypergraph';
43
import { HypergraphSpaceProvider, useHypergraphApp } from '@graphprotocol/hypergraph-react';
54
import { createFileRoute } from '@tanstack/react-router';
@@ -32,7 +31,7 @@ function PlaygroundRouteComponent() {
3231

3332
return (
3433
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
35-
<HypergraphSpaceProvider space={spaceId} mapping={mapping}>
34+
<HypergraphSpaceProvider space={spaceId}>
3635
<TodosPublic />
3736
</HypergraphSpaceProvider>
3837
</div>

apps/events/src/routes/space/$spaceId/public-integration.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { CreatePropertiesAndTypes } from '@/components/create-properties-and-types';
22
import { Todos2 } from '@/components/todos2';
3-
import { mapping } from '@/mapping.js';
43
import { store } from '@graphprotocol/hypergraph';
54
import { HypergraphSpaceProvider, useHypergraphApp } from '@graphprotocol/hypergraph-react';
65
import { createFileRoute } from '@tanstack/react-router';
@@ -33,7 +32,7 @@ function PublicIntegration() {
3332

3433
return (
3534
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
36-
<HypergraphSpaceProvider space={spaceId} mapping={mapping}>
35+
<HypergraphSpaceProvider space={spaceId}>
3736
<CreatePropertiesAndTypes />
3837
<Todos2 />
3938
</HypergraphSpaceProvider>

apps/events/src/routes/space/$spaceId/users.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { UsersMerged } from '@/components/users/users-merged';
22
import { UsersPublic } from '@/components/users/users-public';
3-
import { mapping } from '@/mapping.js';
43
import { store } from '@graphprotocol/hypergraph';
54
import { HypergraphSpaceProvider, useHypergraphApp } from '@graphprotocol/hypergraph-react';
65
import { createFileRoute } from '@tanstack/react-router';
@@ -33,7 +32,7 @@ function UsersRouteComponent() {
3332

3433
return (
3534
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
36-
<HypergraphSpaceProvider space={spaceId} mapping={mapping}>
35+
<HypergraphSpaceProvider space={spaceId}>
3736
<UsersMerged />
3837
<UsersLocal />
3938
<UsersPublic />

apps/next-example/src/components/providers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function Providers({ children }: { children: React.ReactNode }) {
77
const storage = typeof window !== 'undefined' ? window.localStorage : (undefined as unknown as Storage);
88

99
return (
10-
<HypergraphAppProvider storage={storage} syncServerUri="http://localhost:3030">
10+
<HypergraphAppProvider storage={storage} syncServerUri="http://localhost:3030" mapping={{}}>
1111
{children}
1212
</HypergraphAppProvider>
1313
);

packages/hypergraph-react/src/HypergraphAppContext.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
type InboxMessageStorageEntry,
1515
Inboxes,
1616
Key,
17+
type Mapping,
1718
Messages,
1819
SpaceEvents,
1920
type SpaceStorageEntry,
@@ -184,6 +185,7 @@ export type HypergraphAppProviderProps = Readonly<{
184185
syncServerUri?: string;
185186
chainId?: number;
186187
children: ReactNode;
188+
mapping: Mapping;
187189
}>;
188190
// 1) a) Get session token from local storage, or
189191
// b) Auth with the sync server
@@ -193,8 +195,8 @@ export type HypergraphAppProviderProps = Readonly<{
193195
export function HypergraphAppProvider({
194196
storage,
195197
syncServerUri = 'https://syncserver.hypergraph.thegraph.com',
196-
chainId = 80451,
197198
children,
199+
mapping,
198200
}: HypergraphAppProviderProps) {
199201
const [websocketConnection, setWebsocketConnection] = useState<WebSocket>();
200202
const [isConnecting, setIsConnecting] = useState(true);
@@ -227,6 +229,11 @@ export function HypergraphAppProvider({
227229
const initialRenderAuthCheckRef = useRef(false);
228230
// using a layout effect to avoid a re-render
229231
useLayoutEffect(() => {
232+
store.send({
233+
type: 'setMapping',
234+
mapping,
235+
});
236+
230237
if (!initialRenderAuthCheckRef.current) {
231238
const identity = Identity.loadIdentity(storage);
232239
if (identity) {
@@ -238,7 +245,7 @@ export function HypergraphAppProvider({
238245
// set render auth check to true so next potential rerender doesn't proc this
239246
initialRenderAuthCheckRef.current = true;
240247
}
241-
}, [storage]);
248+
}, [storage, mapping]);
242249

243250
useEffect(() => {
244251
if (!identity) {

0 commit comments

Comments
 (0)