@@ -10,9 +10,6 @@ import {
10
10
import {
11
11
useNavigate ,
12
12
} from "react-router-dom"
13
- import {
14
- Form ,
15
- } from "./component/Form.jsx"
16
13
import {
17
14
Button ,
18
15
} from "./component/Button.jsx"
@@ -34,6 +31,12 @@ import {
34
31
import {
35
32
useAuthStore ,
36
33
} from "./store.js"
34
+ import {
35
+ CgClose ,
36
+ } from "react-icons/cg"
37
+ import {
38
+ IconContext ,
39
+ } from "react-icons"
37
40
38
41
const detailData = [
39
42
[ "open" , "Open Games" ] ,
@@ -42,7 +45,6 @@ const detailData = [
42
45
43
46
export function Lobby ( ) {
44
47
let [ isNewGameOpen , setNewGameOpen ] = useState ( false )
45
- let [ isStartEditOpen , setStartEditOpen ] = useState ( false )
46
48
let [ detail , setDetail ] = useState ( "open" )
47
49
let stompClient = useContext ( StompContext )
48
50
let navigate = useNavigate ( )
@@ -75,59 +77,31 @@ export function Lobby() {
75
77
navigate ( base + "/game/" + response . id )
76
78
} ) , [ auth , navigate ] )
77
79
return (
78
- < div className = "mt-4" >
79
- < div className = { twJoin (
80
- "inline-flex py-2 pr-6 gap-x-1" ,
81
- isStartEditOpen && "rounded-r-full bg-slate-400" ,
82
- ) } >
83
- { isStartEditOpen ? (
84
- < StartEditDialog onStartEdit = { onStartEdit } setStartEditOpen = { setStartEditOpen } />
85
- ) : (
86
- < Button className = "ml-2"
87
- onClick = { ( ) => {
88
- setStartEditOpen ( true )
89
- setNewGameOpen ( false )
90
- } } >
91
- Editor
92
- </ Button >
93
- ) }
94
- </ div >
95
- < div className = "clear-both" />
80
+ < div >
96
81
< div className = { twJoin (
97
- "mt-2 inline-flex py-2 pr-6 gap-x-1" ,
98
- isNewGameOpen && "rounded-r-full bg-slate-400" ,
82
+ "mt-2 inline-flex py-2 pr-4 gap-x-1 border-r-2 border-y-2" ,
83
+ isNewGameOpen && "rounded-r-full border-slate-600" ,
84
+ ! isNewGameOpen && "border-transparent" ,
99
85
) } >
100
86
{ isNewGameOpen ? (
101
- < NewGameDialog onNewGame = { onNewGame } setNewGameOpen = { setNewGameOpen } />
87
+ < NewGameDialog
88
+ onNewGame = { onNewGame }
89
+ onStartEdit = { onStartEdit }
90
+ setNewGameOpen = { setNewGameOpen } />
102
91
) : (
103
- < Button className = "ml-2"
92
+ < button className = { twJoin (
93
+ "ml-2 border-2 border-transparent px-4 py-2 rounded-lg" ,
94
+ "hover:border-sky-700" ,
95
+ ) }
104
96
onClick = { ( ) => {
105
- setStartEditOpen ( false )
106
97
setNewGameOpen ( true )
107
98
} } >
108
99
New Game
109
- </ Button >
100
+ </ button >
110
101
) }
111
102
</ div >
112
103
< div className = "clear-both" />
113
- < div className = "mt-2" >
114
- < div className = { twJoin (
115
- "float-left py-3 pl-2 pr-3 bg-slate-700 border-r-2 border-y-2 border-slate-600" ,
116
- "rounded-r-lg flex flex-col gap-y-2" ,
117
- ) } >
118
- { detailData . map ( ( [ id , label ] ) => (
119
- < button
120
- key = { id }
121
- onClick = { ( ) => setDetail ( id ) }
122
- disabled = { id === detail }
123
- className = { twJoin (
124
- "px-2 py-2 rounded-lg border-2" ,
125
- id === detail && "border-slate-600" ,
126
- id !== detail && "border-transparent hover:bg-slate-800 hover:border-slate-600" ,
127
- ) } > { label } </ button >
128
- ) ) }
129
- </ div >
130
- </ div >
104
+ < DetailNavigation detail = { detail } setDetail = { setDetail } />
131
105
{ detail === "open" && (
132
106
< OpenGames />
133
107
) }
@@ -139,34 +113,55 @@ export function Lobby() {
139
113
)
140
114
}
141
115
142
- function NewGameDialog ( { onNewGame, setNewGameOpen} ) {
116
+ function NewGameDialog ( { onNewGame, onStartEdit , setNewGameOpen} ) {
143
117
let dimRef = useRef ( 9 )
118
+ let [ edit , setEdit ] = useState ( false )
144
119
return (
145
- < Form className = "contents" onSubmit = { ( ) => onNewGame ( { dim : dimRef . current } ) } >
146
- < Button onClick = { ( ) => setNewGameOpen ( false ) } className = "ml-2 bg-slate-800 hover:border-slate-800" > Cancel</ Button >
120
+ < form className = "contents" onSubmit = { ( e ) => {
121
+ e . preventDefault ( )
122
+ let game = { dim : dimRef . current }
123
+ if ( edit ) {
124
+ onStartEdit ( game )
125
+ } else {
126
+ onNewGame ( game )
127
+ }
128
+ } } >
129
+ < Button type = "submit" className = "ml-2" > OK</ Button >
147
130
< input id = "dim-9" type = "radio" name = "dim" value = "9" className = "ml-2" defaultChecked = { true } onClick = { ( ) => dimRef . current = 9 } />
148
- < label htmlFor = "dim-9" className = "text-black pt-[0.625rem] pr-1" onClick = { ( ) => dimRef . current = 9 } > 9x9</ label >
131
+ < label htmlFor = "dim-9" className = "pt-[0.625rem] pr-1" > 9x9</ label >
149
132
< input id = "dim-13" type = "radio" name = "dim" value = "13" onClick = { ( ) => dimRef . current = 13 } />
150
- < label htmlFor = "dim-13" className = "text-black pt-[0.625rem] pr-1" onClick = { ( ) => dimRef . current = 13 } > 13x13</ label >
133
+ < label htmlFor = "dim-13" className = "pt-[0.625rem] pr-1" > 13x13</ label >
151
134
< input id = "dim-19" type = "radio" name = "dim" value = "19" onClick = { ( ) => dimRef . current = 19 } />
152
- < label htmlFor = "dim-19" className = "text-black pt-[0.625rem] mr-2" onClick = { ( ) => dimRef . current = 19 } > 19x19</ label >
153
- < Button type = "submit" className = "bg-slate-800 hover:border-slate-800" > OK</ Button >
154
- </ Form >
135
+ < label htmlFor = "dim-19" className = "pt-[0.625rem] pr-1" > 19x19</ label >
136
+ < input id = "cb-edit" type = "checkbox" name = "edit" checked = { edit } onChange = { ( ) => setEdit ( ! edit ) } />
137
+ < label htmlFor = "cb-edit" className = "pt-[0.625rem] ml-1" > Edit</ label >
138
+ < button onClick = { ( ) => setNewGameOpen ( false ) } className = "ml-1 text-stone-100 hover:text-stone-300" >
139
+ < IconContext . Provider value = { { size : "1.25em" } } >
140
+ < CgClose />
141
+ </ IconContext . Provider >
142
+ </ button >
143
+ </ form >
155
144
)
156
145
}
157
-
158
- function StartEditDialog ( { onStartEdit, setStartEditOpen} ) {
159
- let dimRef = useRef ( 9 )
146
+ function DetailNavigation ( { detail, setDetail} ) {
160
147
return (
161
- < Form className = "contents" onSubmit = { ( ) => onStartEdit ( { dim : dimRef . current , editMode : true } ) } >
162
- < Button onClick = { ( ) => setStartEditOpen ( false ) } className = "ml-2 bg-slate-800 hover:border-slate-800" > Cancel</ Button >
163
- < input id = "dim-9" type = "radio" name = "dim" value = "9" className = "ml-2" defaultChecked = { true } onClick = { ( ) => dimRef . current = 9 } />
164
- < label htmlFor = "dim-9" className = "text-black pt-[0.625rem] pr-1" onClick = { ( ) => dimRef . current = 9 } > 9x9</ label >
165
- < input id = "dim-13" type = "radio" name = "dim" value = "13" onClick = { ( ) => dimRef . current = 13 } />
166
- < label htmlFor = "dim-13" className = "text-black pt-[0.625rem] pr-1" onClick = { ( ) => dimRef . current = 13 } > 13x13</ label >
167
- < input id = "dim-19" type = "radio" name = "dim" value = "19" onClick = { ( ) => dimRef . current = 19 } />
168
- < label htmlFor = "dim-19" className = "text-black pt-[0.625rem] mr-2" onClick = { ( ) => dimRef . current = 19 } > 19x19</ label >
169
- < Button type = "submit" className = "bg-slate-800 hover:border-slate-800" > OK</ Button >
170
- </ Form >
148
+ < div className = "mt-2" >
149
+ < div className = { twJoin (
150
+ "float-left py-3 pl-2 pr-3 border-r-2 border-y-2 border-slate-600" ,
151
+ "rounded-r-xl flex flex-col gap-y-2" ,
152
+ ) } >
153
+ { detailData . map ( ( [ id , label ] ) => (
154
+ < button
155
+ key = { id }
156
+ onClick = { ( ) => setDetail ( id ) }
157
+ disabled = { id === detail }
158
+ className = { twJoin (
159
+ "px-2 py-2 rounded-lg border-2 hover:border-sky-700" ,
160
+ id === detail && "border-slate-600" ,
161
+ id !== detail && "border-transparent hover:bg-stone-800" ,
162
+ ) } > { label } </ button >
163
+ ) ) }
164
+ </ div >
165
+ </ div >
171
166
)
172
167
}
0 commit comments