@@ -85,15 +85,68 @@ export function getDefaultConfig(): ClientConfig {
8585 return config
8686}
8787
88- //const ColorRow = (props: { displayName: string, colorName: Colors }) => {
89- // return (
90- // <>
91- // <ColorPicker name={colorName} />
92- // </>
93- // )
94- //}
88+ export const ConfigPage : React . FC < Props > = ( props ) => {
89+ if ( ! props . open ) return null
90+
91+ return (
92+ < div className = { 'flex flex-col' } >
93+ < div className = "mb-2" > Edit Client Config:</ div >
94+ { Object . entries ( DEFAULT_CONFIG ) . map ( ( [ k , v ] ) => {
95+ const key = k as keyof ClientConfig
96+ if ( typeof v === 'string' ) return < ConfigStringElement configKey = { key } key = { key } />
97+ if ( typeof v === 'boolean' ) return < ConfigBooleanElement configKey = { key } key = { key } />
98+ if ( typeof v === 'number' ) return < ConfigNumberElement configKey = { key } key = { key } />
99+ } ) }
100+
101+ < ColorConfig />
102+ </ div >
103+ )
104+ }
105+
106+ const ColorConfig = ( ) => {
107+ const context = useAppContext ( )
108+
109+ /* TODO: [future] do this dynamically rather than hardcoding sections */
110+
111+ return (
112+ < >
113+ < div className = "m-0 mt-4" >
114+ Customize Colors:
115+ < div className = "text-sm pb-1 pt-1" > Interface</ div >
116+ < SingleColorPicker displayName = { 'Background' } colorName = { Colors . GAMEAREA_BACKGROUND } />
117+ < SingleColorPicker displayName = { 'Sidebar' } colorName = { Colors . SIDEBAR_BACKGROUND } />
118+ < div className = "text-sm pb-1" > General</ div >
119+ < SingleColorPicker displayName = { 'Walls' } colorName = { Colors . WALLS_COLOR } />
120+ < SingleColorPicker displayName = { 'Tiles' } colorName = { Colors . TILE_COLOR } />
121+ < div className = "text-sm pb-1" > Silver</ div >
122+ < SingleColorPicker displayName = { 'Text' } colorName = { Colors . TEAM_ONE } />
123+ < SingleColorPicker displayName = { 'Primary Paint' } colorName = { Colors . PAINT_TEAMONE_ONE } />
124+ < SingleColorPicker displayName = { 'Secondary Paint' } colorName = { Colors . PAINT_TEAMONE_TWO } />
125+ < div className = "text-sm pb-1" > Gold</ div >
126+ < SingleColorPicker displayName = { 'Text' } colorName = { Colors . TEAM_TWO } />
127+ < SingleColorPicker displayName = { 'Primary Paint' } colorName = { Colors . PAINT_TEAMTWO_ONE } />
128+ < SingleColorPicker displayName = { 'Secondary Paint' } colorName = { Colors . PAINT_TEAMTWO_TWO } />
129+ </ div >
130+ < div className = "flex flex-row mt-8" >
131+ < BrightButton
132+ className = ""
133+ onClick = { ( ) => {
134+ resetGlobalColors ( )
135+
136+ context . setState ( ( prevState ) => ( {
137+ ...prevState ,
138+ config : { ...prevState . config , colors : { ...DEFAULT_GLOBAL_COLORS } }
139+ } ) )
140+ } }
141+ >
142+ Reset Colors
143+ </ BrightButton >
144+ </ div >
145+ </ >
146+ )
147+ }
95148
96- const ColorPicker = ( props : { displayName : string ; colorName : Colors } ) => {
149+ const SingleColorPicker = ( props : { displayName : string ; colorName : Colors } ) => {
97150 const context = useAppContext ( )
98151 const value = context . state . config . colors [ props . colorName ]
99152 const ref = useRef < HTMLDivElement > ( null )
@@ -110,26 +163,17 @@ const ColorPicker = (props: { displayName: string; colorName: Colors }) => {
110163 setDisplayColorPicker ( false )
111164 }
112165
113- //const handleClickOutside = (event) => {
114- // if (wrapperRef && !wrapperRef.contains(event.target)) {
115- // alert('You clicked outside of me!')
116- // }
117- //}
118-
119166 const handleClickOutside = ( event : any ) => {
120167 if (
121168 ref . current &&
122169 buttonRef . current &&
123170 ! ref . current . contains ( event . target ) &&
124171 ! buttonRef . current . contains ( event . target )
125172 ) {
126- //alert('hi')
127173 handleClose ( )
128174 }
129175 }
130176
131- addEventListener ( 'mousedown' , handleClickOutside )
132-
133177 const onChange = ( newColor : any ) => {
134178 updateGlobalColor ( props . colorName , newColor . hex )
135179 context . setState ( ( prevState ) => ( {
@@ -141,12 +185,15 @@ const ColorPicker = (props: { displayName: string; colorName: Colors }) => {
141185 }
142186
143187 const resetColor = ( ) => {
144- console . log ( DEFAULT_GLOBAL_COLORS )
145- console . log ( props . colorName as Colors )
146- console . log ( DEFAULT_GLOBAL_COLORS [ props . colorName as Colors ] )
147188 onChange ( { hex : DEFAULT_GLOBAL_COLORS [ props . colorName as Colors ] } )
148189 }
149190
191+ useEffect ( ( ) => {
192+ window . addEventListener ( 'mousedown' , handleClickOutside )
193+
194+ return ( ) => window . removeEventListener ( 'mousedown' , handleClickOutside )
195+ } , [ ] )
196+
150197 return (
151198 < >
152199 < div className = { 'ml-2 mb-2 text-xs flex flex-start justify-start items-center' } >
@@ -181,60 +228,6 @@ const ColorPicker = (props: { displayName: string; colorName: Colors }) => {
181228 )
182229}
183230
184- export const ConfigPage : React . FC < Props > = ( props ) => {
185- if ( ! props . open ) return null
186- const context = useAppContext ( )
187-
188- return (
189- < div className = { 'flex flex-col' } >
190- < div className = "mb-2" > Edit Client Config:</ div >
191- { Object . entries ( DEFAULT_CONFIG ) . map ( ( [ k , v ] ) => {
192- const key = k as keyof ClientConfig
193- if ( typeof v === 'string' ) return < ConfigStringElement configKey = { key } key = { key } />
194- if ( typeof v === 'boolean' ) return < ConfigBooleanElement configKey = { key } key = { key } />
195- if ( typeof v === 'number' ) return < ConfigNumberElement configKey = { key } key = { key } />
196- } ) }
197-
198- < div >
199- < br > </ br >
200- </ div >
201- < div className = "color-pickers" >
202- { /*fake class*/ }
203- Customize Colors:
204- < div className = "text-sm pb-1 pt-1" > Interface</ div >
205- < ColorPicker displayName = { 'Background' } colorName = { Colors . GAMEAREA_BACKGROUND } />
206- < ColorPicker displayName = { 'Sidebar' } colorName = { Colors . SIDEBAR_BACKGROUND } />
207- < div className = "text-sm pb-1" > General</ div >
208- < ColorPicker displayName = { 'Walls' } colorName = { Colors . WALLS_COLOR } />
209- < ColorPicker displayName = { 'Tiles' } colorName = { Colors . TILE_COLOR } />
210- < div className = "text-sm pb-1" > Silver</ div >
211- < ColorPicker displayName = { 'Text' } colorName = { Colors . TEAM_ONE } />
212- < ColorPicker displayName = { 'Primary Paint' } colorName = { Colors . PAINT_TEAMONE_ONE } />
213- < ColorPicker displayName = { 'Secondary Paint' } colorName = { Colors . PAINT_TEAMONE_TWO } />
214- < div className = "text-sm pb-1" > Gold</ div >
215- < ColorPicker displayName = { 'Text' } colorName = { Colors . TEAM_TWO } />
216- < ColorPicker displayName = { 'Primary Paint' } colorName = { Colors . PAINT_TEAMTWO_ONE } />
217- < ColorPicker displayName = { 'Secondary Paint' } colorName = { Colors . PAINT_TEAMTWO_TWO } />
218- </ div >
219- < div className = "flex flex-row mt-8" >
220- < BrightButton
221- className = ""
222- onClick = { ( ) => {
223- resetGlobalColors ( )
224-
225- context . setState ( ( prevState ) => ( {
226- ...prevState ,
227- config : { ...prevState . config , colors : { ...DEFAULT_GLOBAL_COLORS } }
228- } ) )
229- } }
230- >
231- Reset Colors
232- </ BrightButton >
233- </ div >
234- </ div >
235- )
236- }
237-
238231const ConfigBooleanElement : React . FC < { configKey : keyof ClientConfig } > = ( { configKey } ) => {
239232 const context = useAppContext ( )
240233 const value = context . state . config [ configKey ] as boolean
0 commit comments