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
5 changes: 3 additions & 2 deletions apps/events/src/components/playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useState } from 'react';
import { Event } from '../schema';
import { Button } from './ui/button';

export const Playground = () => {
export const Playground = ({ spaceId }: { spaceId: string }) => {
const { data, isLoading, isError } = useQuery(Event, {
mode: 'public',
include: {
Expand All @@ -18,12 +18,13 @@ export const Playground = () => {
},
},
first: 2,
space: spaceId,
});
const [isDeleting, setIsDeleting] = useState(false);
const [isCreating, setIsCreating] = useState(false);
const { getSmartSessionClient } = useHypergraphApp();

const { name, id: spaceId } = useSpace({ mode: 'public' });
const { name } = useSpace({ mode: 'public', space: spaceId });

const deleteEntity = _useDeleteEntityPublic(Event, { space: spaceId });
const createEntity = _useCreateEntityPublic(Event, { space: spaceId });
Expand Down
18 changes: 10 additions & 8 deletions apps/events/src/routes/playground.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export const Route = createLazyFileRoute('/playground')({
function RouteComponent() {
const space = 'a393e509-ae56-4d99-987c-bed71d9db631';
return (
<HypergraphSpaceProvider space={space}>
<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 space={space} />
<CreateEvents space={space} />
</div>
</HypergraphSpaceProvider>
<>
<Playground spaceId={space} />
<HypergraphSpaceProvider space={space}>
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
<h1 className="text-2xl font-bold">Playground</h1>
<CreatePropertiesAndTypesEvent space={space} />
<CreateEvents space={space} />
</div>
</HypergraphSpaceProvider>
</>
);
}
2 changes: 1 addition & 1 deletion packages/hypergraph-react/src/HypergraphSpaceContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const HypergraphReactContext = createContext<HypergraphContext | undefine

export function useHypergraphSpaceInternal() {
const context = useContext(HypergraphReactContext);
return context as HypergraphContext;
return (context as HypergraphContext) || { space: '' };
Copy link

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

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

Fallbacking to an empty string when context is missing can mask missing provider issues. Consider throwing an error or logging a warning to catch unintended usage early.

Suggested change
return (context as HypergraphContext) || { space: '' };
if (!context) {
throw new Error('HypergraphReactContext provider is missing. Ensure that HypergraphSpaceProvider is used.');
}
return context as HypergraphContext;

Copilot uses AI. Check for mistakes.

}

export function HypergraphSpaceProvider({ space, children }: { space: string; children: ReactNode }) {
Expand Down
1 change: 1 addition & 0 deletions packages/hypergraph-react/src/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type * as Schema from 'effect/Schema';

export type QueryPublicParams<S extends Entity.AnyNoContext> = {
enabled: boolean;
space?: string | undefined;
// TODO: for multi-level nesting it should only allow the allowed properties instead of Record<string, Record<string, never>>
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
first?: number | undefined;
Expand Down
5 changes: 3 additions & 2 deletions packages/hypergraph-react/src/internal/use-query-public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,9 @@ export const parseResult = <S extends Entity.AnyNoContext>(
};

export const useQueryPublic = <S extends Entity.AnyNoContext>(type: S, params?: QueryPublicParams<S>) => {
const { enabled = true, include, first = 100 } = params ?? {};
const { space } = useHypergraphSpaceInternal();
const { enabled = true, include, space: spaceFromParams, first = 100 } = params ?? {};
const { space: spaceFromContext } = useHypergraphSpaceInternal();
const space = spaceFromParams ?? spaceFromContext;
const mapping = useSelector(store, (state) => state.context.mapping);

// @ts-expect-error TODO should use the actual type instead of the name in the mapping
Expand Down
4 changes: 2 additions & 2 deletions packages/hypergraph-react/src/use-query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type QueryParams<S extends Entity.AnyNoContext> = {
filter?: { [K in keyof Schema.Schema.Type<S>]?: Entity.EntityFieldFilter<Schema.Schema.Type<S>[K]> } | undefined;
// TODO: for multi-level nesting it should only allow the allowed properties instead of Record<string, Record<string, never>>
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
space?: string;
space?: string | undefined;
Copy link

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

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

[nitpick] The explicit | undefined is redundant for an optional property; you can simplify this to space?: string for clarity.

Suggested change
space?: string | undefined;
space?: string;

Copilot uses AI. Check for mistakes.

first?: number | undefined;
};

Expand Down Expand Up @@ -146,7 +146,7 @@ const preparePublishDummy = () => undefined;

export function useQuery<const S extends Entity.AnyNoContext>(type: S, params: QueryParams<S>) {
const { mode, filter, include, space, first } = params;
const publicResult = useQueryPublic(type, { enabled: mode === 'public', include, first });
const publicResult = useQueryPublic(type, { enabled: mode === 'public', include, first, space });
const localResult = useQueryLocal(type, { enabled: mode === 'private', filter, include, space });
// const mapping = useSelector(store, (state) => state.context.mapping);
// const generateUpdateOps = useGenerateUpdateOps(type, mode === 'merged');
Expand Down
Loading