Skip to content

Commit 31be751

Browse files
committed
fix space id extraction
1 parent 6fc00da commit 31be751

6 files changed

Lines changed: 20 additions & 15 deletions

File tree

apps/events/src/components/playground.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@ import { useState } from 'react';
99
import { Event } from '../schema';
1010
import { Button } from './ui/button';
1111

12-
export const Playground = () => {
12+
export const Playground = ({ spaceId }: { spaceId: string }) => {
1313
const { data, isLoading, isError } = useQuery(Event, {
1414
mode: 'public',
1515
include: {
1616
sponsors: {
1717
jobOffers: {},
1818
},
1919
},
20+
space: spaceId,
2021
});
2122
const [isDeleting, setIsDeleting] = useState(false);
2223
const [isCreating, setIsCreating] = useState(false);
2324
const { getSmartSessionClient } = useHypergraphApp();
2425

25-
const { name, id: spaceId } = useSpace({ mode: 'public' });
26+
const { name } = useSpace({ mode: 'public', space: spaceId });
2627

2728
const deleteEntity = _useDeleteEntityPublic(Event, { space: spaceId });
2829
const createEntity = _useCreateEntityPublic(Event, { space: spaceId });

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ export const Route = createLazyFileRoute('/playground')({
1111
function RouteComponent() {
1212
const space = 'a393e509-ae56-4d99-987c-bed71d9db631';
1313
return (
14-
<HypergraphSpaceProvider space={space}>
15-
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
16-
<h1 className="text-2xl font-bold">Playground</h1>
17-
<Playground />
18-
<CreatePropertiesAndTypesEvent space={space} />
19-
<CreateEvents space={space} />
20-
</div>
21-
</HypergraphSpaceProvider>
14+
<>
15+
<Playground spaceId={space} />
16+
<HypergraphSpaceProvider space={space}>
17+
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
18+
<h1 className="text-2xl font-bold">Playground</h1>
19+
<CreatePropertiesAndTypesEvent space={space} />
20+
<CreateEvents space={space} />
21+
</div>
22+
</HypergraphSpaceProvider>
23+
</>
2224
);
2325
}

packages/hypergraph-react/src/HypergraphSpaceContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const HypergraphReactContext = createContext<HypergraphContext | undefine
2323

2424
export function useHypergraphSpaceInternal() {
2525
const context = useContext(HypergraphReactContext);
26-
return context as HypergraphContext;
26+
return (context as HypergraphContext) || { space: '' };
2727
}
2828

2929
export function HypergraphSpaceProvider({ space, children }: { space: string; children: ReactNode }) {

packages/hypergraph-react/src/internal/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type * as Schema from 'effect/Schema';
33

44
export type QueryPublicParams<S extends Entity.AnyNoContext> = {
55
enabled: boolean;
6+
space?: string | undefined;
67
// TODO: for multi-level nesting it should only allow the allowed properties instead of Record<string, Record<string, never>>
78
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
89
};

packages/hypergraph-react/src/internal/use-query-public.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,9 @@ export const parseResult = <S extends Entity.AnyNoContext>(
290290
};
291291

292292
export const useQueryPublic = <S extends Entity.AnyNoContext>(type: S, params?: QueryPublicParams<S>) => {
293-
const { enabled = true, include } = params ?? {};
294-
const { space } = useHypergraphSpaceInternal();
293+
const { enabled = true, include, space: spaceFromParams } = params ?? {};
294+
const { space: spaceFromContext } = useHypergraphSpaceInternal();
295+
const space = spaceFromParams ?? spaceFromContext;
295296
const mapping = useSelector(store, (state) => state.context.mapping);
296297

297298
// @ts-expect-error TODO should use the actual type instead of the name in the mapping

packages/hypergraph-react/src/use-query.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type QueryParams<S extends Entity.AnyNoContext> = {
99
filter?: { [K in keyof Schema.Schema.Type<S>]?: Entity.EntityFieldFilter<Schema.Schema.Type<S>[K]> } | undefined;
1010
// TODO: for multi-level nesting it should only allow the allowed properties instead of Record<string, Record<string, never>>
1111
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
12-
space?: string;
12+
space?: string | undefined;
1313
};
1414

1515
// @ts-expect-error TODO: remove this function
@@ -145,7 +145,7 @@ const preparePublishDummy = () => undefined;
145145

146146
export function useQuery<const S extends Entity.AnyNoContext>(type: S, params: QueryParams<S>) {
147147
const { mode, filter, include, space } = params;
148-
const publicResult = useQueryPublic(type, { enabled: mode === 'public', include });
148+
const publicResult = useQueryPublic(type, { enabled: mode === 'public', include, space });
149149
const localResult = useQueryLocal(type, { enabled: mode === 'private', filter, include, space });
150150
// const mapping = useSelector(store, (state) => state.context.mapping);
151151
// const generateUpdateOps = useGenerateUpdateOps(type, mode === 'merged');

0 commit comments

Comments
 (0)