-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
react-sdk: auth status, space, channels, actions (#326)
This PR adds - [x] choose environment - [x] fund wallet - [x] log in - [x] create space - [x] render spaces - [x] render space channels - [x] render timelines - [x] send message in channel Also changes the implementation of `useObservable` to start using `useSyncExternalStore` --------- Co-authored-by: texuf <[email protected]>
- Loading branch information
1 parent
59fb24f
commit 64bb70e
Showing
46 changed files
with
1,722 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useRiverAuthStatus } from '@river-build/react-sdk' | ||
import { Block } from '../ui/block' | ||
|
||
export const UserAuthStatusBlock = () => { | ||
const { status } = useRiverAuthStatus() | ||
return <Block title="User Auth Status">{JSON.stringify(status, null, 2)}</Block> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { useChannel, useCreateChannel, useSpace } from '@river-build/react-sdk' | ||
import { zodResolver } from '@hookform/resolvers/zod' | ||
import { useForm } from 'react-hook-form' | ||
import { z } from 'zod' | ||
import { useEthersSigner } from '@/utils/viem-to-ethers' | ||
import { useCurrentSpaceId } from '@/hooks/current-space' | ||
import { | ||
Form, | ||
FormControl, | ||
FormDescription, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from '../ui/form' | ||
import { Block, type BlockProps } from '../ui/block' | ||
import { Button } from '../ui/button' | ||
import { Input } from '../ui/input' | ||
import { JsonHover } from '../utils/json-hover' | ||
|
||
type ChannelsBlockProps = { | ||
changeChannel: (channelId: string) => void | ||
} | ||
|
||
const formSchema = z.object({ | ||
channelName: z.string().min(1, { message: 'Space name is required' }), | ||
}) | ||
|
||
export const ChannelsBlock = ({ changeChannel }: ChannelsBlockProps) => { | ||
const spaceId = useCurrentSpaceId() | ||
const { data: space } = useSpace(spaceId) | ||
|
||
return ( | ||
<Block title={`Channels in ${space.metadata?.name || 'Unnamed Space'}`}> | ||
<CreateChannel variant="secondary" spaceId={spaceId} onChannelCreated={changeChannel} /> | ||
<div className="flex flex-col gap-1"> | ||
<span className="text-xs">Select a channel to start messaging</span> | ||
{space.channelIds.map((channelId) => ( | ||
<ChannelInfo | ||
key={`${spaceId}-${channelId}`} | ||
spaceId={space.id} | ||
channelId={channelId} | ||
changeChannel={changeChannel} | ||
/> | ||
))} | ||
</div> | ||
{space.channelIds.length === 0 && ( | ||
<p className="pt-4 text-center text-sm text-secondary-foreground"> | ||
You're not in any Channels yet. | ||
</p> | ||
)} | ||
</Block> | ||
) | ||
} | ||
|
||
const ChannelInfo = ({ | ||
spaceId, | ||
channelId, | ||
changeChannel, | ||
}: { | ||
spaceId: string | ||
channelId: string | ||
changeChannel: (channelId: string) => void | ||
}) => { | ||
const { data: channel } = useChannel(spaceId, channelId) | ||
|
||
return ( | ||
<JsonHover data={channel}> | ||
<div> | ||
<Button variant="outline" onClick={() => changeChannel(channelId)}> | ||
{channel.metadata?.name || 'Unnamed Channel'} | ||
</Button> | ||
</div> | ||
</JsonHover> | ||
) | ||
} | ||
|
||
export const CreateChannel = ( | ||
props: { | ||
spaceId: string | ||
onChannelCreated: (channelId: string) => void | ||
} & BlockProps, | ||
) => { | ||
const { onChannelCreated, spaceId, ...rest } = props | ||
const { createChannel, isPending } = useCreateChannel(spaceId) | ||
const signer = useEthersSigner() | ||
const form = useForm<z.infer<typeof formSchema>>({ | ||
resolver: zodResolver(formSchema), | ||
defaultValues: { channelName: '' }, | ||
}) | ||
|
||
// TODO: this should be a dialog | ||
return ( | ||
<Block {...rest}> | ||
<Form {...form}> | ||
<form | ||
className="space-y-8" | ||
onSubmit={form.handleSubmit(async ({ channelName }) => { | ||
if (!signer) { | ||
return | ||
} | ||
const channelId = await createChannel(channelName, signer) | ||
onChannelCreated(channelId) | ||
})} | ||
> | ||
<FormField | ||
control={form.control} | ||
name="channelName" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>New channel name</FormLabel> | ||
<FormControl> | ||
{/* TODO: input mask so it start with # but gets stripped */} | ||
<Input placeholder="#cool-photos" {...field} /> | ||
</FormControl> | ||
<FormDescription> | ||
This will be the name of your channel. | ||
</FormDescription> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<Button type="submit"> {isPending ? 'Creating...' : 'Create'}</Button> | ||
</form> | ||
</Form> | ||
</Block> | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/playground/src/components/blocks/connection-block.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useRiver, useRiverConnection } from '@river-build/react-sdk' | ||
import { Block } from '../ui/block' | ||
|
||
export const ConnectionBlock = () => { | ||
const { isConnected } = useRiverConnection() | ||
const { data: nodeUrls } = useRiver((s) => s.riverStreamNodeUrls) | ||
|
||
return ( | ||
<Block title={`Sync Connection ${isConnected ? '✅' : '❌'}`} className="rounded-lg"> | ||
<Block variant="secondary"> | ||
<pre className="overflow-auto whitespace-pre-wrap"> | ||
{JSON.stringify(nodeUrls, null, 2)} | ||
</pre> | ||
</Block> | ||
</Block> | ||
) | ||
} |
Oops, something went wrong.