@@ -8,6 +8,7 @@ import { Command as CommandPrimitive } from "cmdk";
88import { useState } from "react" ;
99import { useForm } from "react-hook-form" ;
1010import { zodResolver } from "@hookform/resolvers/zod" ;
11+ import { ChainSwitch } from "../../../../components/ChainSwitch" ;
1112import { Button } from "../../../../components/ui/Button" ;
1213import { Command , CommandGroup , CommandItem , CommandList } from "../../../../components/ui/Command" ;
1314import { Form , FormControl , FormField , FormItem , FormMessage } from "../../../../components/ui/Form" ;
@@ -39,16 +40,16 @@ export function WorldsForm({ worlds, isLoading }: Props) {
3940 reValidateMode : "onChange" ,
4041 } ) ;
4142
42- function onSubmit ( { worldAddress } : z . infer < typeof formSchema > ) {
43+ const onSubmit = ( { worldAddress } : z . infer < typeof formSchema > ) => {
4344 router . push ( getWorldUrl ( chainName as string , worldAddress ) ) ;
44- }
45+ } ;
4546
46- function onLuckyWorld ( ) {
47+ const onLuckyWorld = ( ) => {
4748 if ( worlds . length > 0 ) {
4849 const luckyAddress = worlds [ Math . floor ( Math . random ( ) * worlds . length ) ] ;
4950 router . push ( getWorldUrl ( chainName as string , luckyAddress as Address ) ) ;
5051 }
51- }
52+ } ;
5253
5354 const handleOpenOptions = ( ) => {
5455 if ( ! open && worlds . length > 0 ) {
@@ -66,40 +67,46 @@ export function WorldsForm({ worlds, isLoading }: Props) {
6667 < Form { ...form } >
6768 < form onSubmit = { form . handleSubmit ( onSubmit ) } className = "space-y-6" >
6869 < div >
69- < FormField
70- control = { form . control }
71- name = "worldAddress"
72- render = { ( { field } ) => (
73- < FormItem >
74- < FormControl >
75- < CommandPrimitive . Input
76- asChild
77- value = { field . value }
78- onValueChange = { ( value ) => {
79- field . onChange ( value ) ;
80- } }
81- onBlur = { ( ) => {
82- field . onBlur ( ) ;
83- setOpen ( false ) ;
84- } }
85- onFocus = { handleOpenOptions }
86- placeholder = { isLoading ? "Loading worlds..." : "Enter world address..." }
87- // Need to manually trigger form submission as CommandPrimitive.Input captures Enter key events
88- onKeyDown = { ( e ) => {
89- if ( ! open && e . key === "Enter" ) {
90- e . preventDefault ( ) ;
91- form . handleSubmit ( onSubmit ) ( ) ;
92- }
93- } }
94- disabled = { isLoading }
95- >
96- < Input className = "h-12" />
97- </ CommandPrimitive . Input >
98- </ FormControl >
99- < FormMessage className = "uppercase" />
100- </ FormItem >
101- ) }
102- />
70+ < div className = "flex items-center gap-x-2" >
71+ < div className = "w-[260px] flex-shrink-0" >
72+ < FormField
73+ control = { form . control }
74+ name = "worldAddress"
75+ render = { ( { field } ) => (
76+ < FormItem >
77+ < FormControl >
78+ < CommandPrimitive . Input
79+ asChild
80+ value = { field . value }
81+ onValueChange = { ( value ) => {
82+ field . onChange ( value ) ;
83+ } }
84+ onBlur = { ( ) => {
85+ field . onBlur ( ) ;
86+ setOpen ( false ) ;
87+ } }
88+ onFocus = { handleOpenOptions }
89+ placeholder = { isLoading ? "Loading worlds..." : "Enter world address..." }
90+ // Need to manually trigger form submission as CommandPrimitive.Input captures Enter key events
91+ onKeyDown = { ( e ) => {
92+ if ( ! open && e . key === "Enter" ) {
93+ e . preventDefault ( ) ;
94+ form . handleSubmit ( onSubmit ) ( ) ;
95+ }
96+ } }
97+ disabled = { isLoading }
98+ >
99+ < Input className = "h-12" />
100+ </ CommandPrimitive . Input >
101+ </ FormControl >
102+ < FormMessage className = "uppercase" />
103+ </ FormItem >
104+ ) }
105+ />
106+ </ div >
107+
108+ < ChainSwitch className = "w-full" />
109+ </ div >
103110
104111 < div className = "relative" >
105112 < CommandList >
0 commit comments