diff --git a/packages/playground/src/components/blocks/channels.tsx b/packages/playground/src/components/blocks/channels.tsx index 676d607dc..dcf0e5b99 100644 --- a/packages/playground/src/components/blocks/channels.tsx +++ b/packages/playground/src/components/blocks/channels.tsx @@ -33,16 +33,18 @@ export const ChannelsBlock = ({ changeChannel }: ChannelsBlockProps) => { return ( -
+
Select a channel to start messaging - {space.channelIds.map((channelId) => ( - - ))} +
+ {space.channelIds.map((channelId) => ( + + ))} +
{space.channelIds.length === 0 && (

@@ -94,7 +96,7 @@ export const CreateChannel = (

{ if (!signer) { return diff --git a/packages/playground/src/components/blocks/spaces.tsx b/packages/playground/src/components/blocks/spaces.tsx index 0b25abd29..e3c6d8ce0 100644 --- a/packages/playground/src/components/blocks/spaces.tsx +++ b/packages/playground/src/components/blocks/spaces.tsx @@ -1,4 +1,4 @@ -import { useCreateSpace, useSpace, useUserSpaces } from '@river-build/react-sdk' +import { useCreateSpace, useJoinSpace, useSpace, useUserSpaces } from '@river-build/react-sdk' import { zodResolver } from '@hookform/resolvers/zod' import { useForm } from 'react-hook-form' import { z } from 'zod' @@ -21,7 +21,7 @@ type SpacesBlockProps = { changeSpace: (spaceId: string) => void } -const formSchema = z.object({ +const createSpaceFormSchema = z.object({ spaceName: z.string().min(1, { message: 'Space name is required' }), }) @@ -30,6 +30,7 @@ export const SpacesBlock = ({ changeSpace }: SpacesBlockProps) => { return ( + Select a space to start messaging
{spaceIds.map((spaceId) => ( @@ -64,13 +65,63 @@ const SpaceInfo = ({ ) } +const joinSpaceFormSchema = z.object({ + spaceId: z.string().min(1, { message: 'Space Id is required' }), +}) +export const JoinSpace = (props: { onJoinSpace: (spaceId: string) => void } & BlockProps) => { + const { onJoinSpace, ...rest } = props + const { joinSpace, isPending } = useJoinSpace() + const signer = useEthersSigner() + + const form = useForm>({ + resolver: zodResolver(joinSpaceFormSchema), + defaultValues: { spaceId: '' }, + }) + + return ( + + + { + if (!signer) { + return + } + joinSpace(spaceId, signer).then(() => { + onJoinSpace(spaceId) + }) + })} + > + ( + + Join Space + + + + + The spaceId of the space you want to join. + + + + )} + /> + + + + + ) +} + export const CreateSpace = (props: { onCreateSpace: (spaceId: string) => void } & BlockProps) => { const { onCreateSpace, ...rest } = props const { createSpace, isPending } = useCreateSpace() const signer = useEthersSigner() - const form = useForm>({ - resolver: zodResolver(formSchema), + const form = useForm>({ + resolver: zodResolver(createSpaceFormSchema), defaultValues: { spaceName: '' }, }) @@ -78,7 +129,7 @@ export const CreateSpace = (props: { onCreateSpace: (spaceId: string) => void }
{ if (!signer) { return diff --git a/packages/playground/src/components/ui/input.tsx b/packages/playground/src/components/ui/input.tsx index 592b0bbbd..3f767f23e 100644 --- a/packages/playground/src/components/ui/input.tsx +++ b/packages/playground/src/components/ui/input.tsx @@ -9,6 +9,8 @@ const Input = React.forwardRef( return ( { } return ( - + = {}) => { +export const useJoinSpace = (config: ActionConfig = {}) => { const sync = useSyncAgent() - const space = sync.spaces.getSpace(spaceId) - const { action: join, ...rest } = useAction(space, 'join', config) + const { action: joinSpace, ...rest } = useAction(sync.spaces, 'joinSpace', config) return { - join, + joinSpace, ...rest, } } diff --git a/packages/sdk/src/sync-agent/spaces/spaces.ts b/packages/sdk/src/sync-agent/spaces/spaces.ts index c155609ab..189cddc2e 100644 --- a/packages/sdk/src/sync-agent/spaces/spaces.ts +++ b/packages/sdk/src/sync-agent/spaces/spaces.ts @@ -115,4 +115,9 @@ export class Spaces extends PersistedObservable { }) return { spaceId, defaultChannelId } } + + async joinSpace(spaceId: string, ...args: Parameters) { + const space = this.getSpace(spaceId) + return space.join(...args) + } }