Skip to content

Commit d024ba6

Browse files
authored
export only useful functions (#139)
1 parent e898cdb commit d024ba6

File tree

13 files changed

+49
-49
lines changed

13 files changed

+49
-49
lines changed

apps/events/src/Boot.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RouterProvider, createRouter } from '@tanstack/react-router';
22

3-
import { Hypergraph } from '@graphprotocol/hypergraph-react';
3+
import { HypergraphAppProvider } from '@graphprotocol/hypergraph-react';
44
import { PrivyProvider } from '@privy-io/react-auth';
55

66
import { routeTree } from './routeTree.gen';
@@ -33,9 +33,9 @@ export function Boot() {
3333
},
3434
}}
3535
>
36-
<Hypergraph.HypergraphAppProvider storage={localStorage}>
36+
<HypergraphAppProvider storage={localStorage}>
3737
<RouterProvider router={router} />
38-
</Hypergraph.HypergraphAppProvider>
38+
</HypergraphAppProvider>
3939
</PrivyProvider>
4040
);
4141
}

apps/events/src/components/dev-tool.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { store } from '@graphprotocol/hypergraph';
2-
import { Hypergraph } from '@graphprotocol/hypergraph-react';
2+
import { useHypergraphApp } from '@graphprotocol/hypergraph-react';
33
import { useSelector } from '@xstate/store/react';
44
import { useEffect, useState } from 'react';
55

@@ -10,7 +10,7 @@ export function DevTool({ spaceId }: { spaceId: string }) {
1010

1111
const spaces = useSelector(store, (state) => state.context.spaces);
1212
const updatesInFlight = useSelector(store, (state) => state.context.updatesInFlight);
13-
const { subscribeToSpace, loading } = Hypergraph.useHypergraphApp();
13+
const { subscribeToSpace, loading } = useHypergraphApp();
1414

1515
useEffect(() => {
1616
if (!loading) {

apps/events/src/components/logout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Hypergraph } from '@graphprotocol/hypergraph-react';
1+
import { useHypergraphApp } from '@graphprotocol/hypergraph-react';
22
import { usePrivy } from '@privy-io/react-auth';
33
import { useRouter } from '@tanstack/react-router';
44
import { Button } from './ui/button';
55

66
export function Logout() {
7-
const { logout: graphLogout } = Hypergraph.useHypergraphApp();
7+
const { logout: graphLogout } = useHypergraphApp();
88
const { logout: privyLogout } = usePrivy();
99
const router = useRouter();
1010
const disconnectWallet = async () => {

apps/events/src/components/todos.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { Space } from '@graphprotocol/hypergraph-react';
1+
import { useCreateEntity, useDeleteEntity, useQueryEntities, useUpdateEntity } from '@graphprotocol/hypergraph-react';
22
import { useState } from 'react';
33
import { Todo } from '../schema';
44
import { Button } from './ui/button';
55
import { Input } from './ui/input';
66

77
export const Todos = () => {
8-
const todos = Space.useQueryEntities(Todo);
9-
const createEntity = Space.useCreateEntity(Todo);
10-
const updateEntity = Space.useUpdateEntity(Todo);
11-
const deleteEntity = Space.useDeleteEntity();
8+
const todos = useQueryEntities(Todo);
9+
const createEntity = useCreateEntity(Todo);
10+
const updateEntity = useUpdateEntity(Todo);
11+
const deleteEntity = useDeleteEntity();
1212
const [newTodoTitle, setNewTodoTitle] = useState('');
1313

1414
return (

apps/events/src/routes/__root.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { Logout } from '@/components/logout';
2-
import { Hypergraph } from '@graphprotocol/hypergraph-react';
2+
import { useHypergraphAuth } from '@graphprotocol/hypergraph-react';
33
import { Link, Outlet, createRootRoute, useLayoutEffect, useRouter } from '@tanstack/react-router';
44
import { TanStackRouterDevtools } from '@tanstack/router-devtools';
55

66
export const Route = createRootRoute({
77
component: () => {
8-
const authenticated = Hypergraph.useAuthenticated();
9-
const graphIdentity = Hypergraph.useHypergraphIdentity();
8+
const { authenticated, identity } = useHypergraphAuth();
109

1110
const router = useRouter();
1211

@@ -33,7 +32,7 @@ export const Route = createRootRoute({
3332
{authenticated ? (
3433
<div className="flex items-center gap-2">
3534
<span className="text-xs text-gray-500 dark:text-gray-400">
36-
{graphIdentity?.accountId.substring(0, 6)}
35+
{identity?.accountId.substring(0, 6)}
3736
</span>
3837
<Logout />
3938
</div>

apps/events/src/routes/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { store } from '@graphprotocol/hypergraph';
2-
import { Hypergraph } from '@graphprotocol/hypergraph-react';
2+
import { useHypergraphApp } from '@graphprotocol/hypergraph-react';
33
import { Link, createFileRoute } from '@tanstack/react-router';
44
import { useSelector } from '@xstate/store/react';
55
import { useEffect } from 'react';
@@ -13,8 +13,7 @@ export const Route = createFileRoute('/')({
1313

1414
function Index() {
1515
const spaces = useSelector(store, (state) => state.context.spaces);
16-
const { createSpace, listSpaces, listInvitations, invitations, acceptInvitation, loading } =
17-
Hypergraph.useHypergraphApp();
16+
const { createSpace, listSpaces, listInvitations, invitations, acceptInvitation, loading } = useHypergraphApp();
1817

1918
console.log('Home page', { loading });
2019

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Identity } from '@graphprotocol/hypergraph';
2-
import { Hypergraph } from '@graphprotocol/hypergraph-react';
2+
import { useHypergraphApp } from '@graphprotocol/hypergraph-react';
33
import { usePrivy, useWallets } from '@privy-io/react-auth';
44
import { createLazyFileRoute, useRouter } from '@tanstack/react-router';
55
import { Loader2 } from 'lucide-react';
@@ -17,7 +17,7 @@ export const Route = createLazyFileRoute('/login')({
1717
function Login() {
1818
const { ready: privyReady, login: privyLogin, signMessage, authenticated: privyAuthenticated } = usePrivy();
1919
const { ready: walletsReady, wallets } = useWallets();
20-
const { setIdentityAndSessionToken, login: hypergraphLogin } = Hypergraph.useHypergraphApp();
20+
const { setIdentityAndSessionToken, login: hypergraphLogin } = useHypergraphApp();
2121
const { navigate } = useRouter();
2222
const [hypergraphLoginStarted, setHypergraphLoginStarted] = useState(false);
2323

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { store } from '@graphprotocol/hypergraph';
2-
import { Hypergraph, Space as HypergraphSpace } from '@graphprotocol/hypergraph-react';
2+
import { HypergraphSpaceProvider, useHypergraphApp } from '@graphprotocol/hypergraph-react';
33
import { createFileRoute } from '@tanstack/react-router';
44
import { useSelector } from '@xstate/store/react';
55

@@ -17,7 +17,7 @@ export const Route = createFileRoute('/space/$spaceId')({
1717
function Space() {
1818
const { spaceId } = Route.useParams();
1919
const spaces = useSelector(store, (state) => state.context.spaces);
20-
const { subscribeToSpace, inviteToSpace, loading } = Hypergraph.useHypergraphApp();
20+
const { subscribeToSpace, inviteToSpace, loading } = useHypergraphApp();
2121
useEffect(() => {
2222
if (!loading) {
2323
subscribeToSpace({ spaceId });
@@ -36,7 +36,7 @@ function Space() {
3636

3737
return (
3838
<div className="flex flex-col gap-4 max-w-screen-sm mx-auto py-8">
39-
<HypergraphSpace.HypergraphProvider space={spaceId}>
39+
<HypergraphSpaceProvider space={spaceId}>
4040
<Todos />
4141
<h3 className="text-xl font-bold">Invite people</h3>
4242
<div className="flex flex-row gap-2">
@@ -59,7 +59,7 @@ function Space() {
5959
<div className="mt-12">
6060
<DevTool spaceId={spaceId} />
6161
</div>
62-
</HypergraphSpace.HypergraphProvider>
62+
</HypergraphSpaceProvider>
6363
</div>
6464
);
6565
}

packages/hypergraph-react/src/HypergraphAppContext.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,9 @@ export function useHypergraphApp() {
7777
return useContext<HypergraphAppCtx>(HypergraphAppContext);
7878
}
7979

80-
export function useAuthenticated() {
81-
return useSelectorStore(store, (state) => state.context.authenticated);
82-
}
83-
export function useHypergraphAccountId() {
84-
return useSelectorStore(store, (state) => state.context.accountId);
85-
}
86-
export function useHypergraphIdentity() {
87-
const accountId = useHypergraphAccountId();
80+
export function useHypergraphAuth() {
81+
const authenticated = useSelectorStore(store, (state) => state.context.authenticated);
82+
const accountId = useSelectorStore(store, (state) => state.context.accountId);
8883
const keys = useSelectorStore(store, (state) => state.context.keys);
8984
const identity: Identity.Identity | null =
9085
accountId && keys
@@ -96,10 +91,7 @@ export function useHypergraphIdentity() {
9691
signaturePrivateKey: keys.signaturePrivateKey,
9792
}
9893
: null;
99-
return identity;
100-
}
101-
export function useHypergraphSessionToken() {
102-
return useSelectorStore(store, (state) => state.context.sessionToken);
94+
return { authenticated, identity };
10395
}
10496

10597
export type HypergraphAppProviderProps = Readonly<{

packages/hypergraph-react/src/HypergraphSpaceContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function useHypergraph() {
2424
return context as HypergraphContext;
2525
}
2626

27-
export function HypergraphProvider({ space, children }: { space: string; children: ReactNode }) {
27+
export function HypergraphSpaceProvider({ space, children }: { space: string; children: ReactNode }) {
2828
const repo = useRepo();
2929
const ref = useRef<HypergraphContext | undefined>(undefined);
3030

0 commit comments

Comments
 (0)