@@ -26,7 +26,6 @@ const Join = ({ location }) => {
26
26
`Ensure username and/or room name is clean` ,
27
27
] ) ;
28
28
const [ error , setError ] = useState ( obj . error ) ;
29
- const [ defaultRoom , setDefaultRoom ] = useState ( "" ) ;
30
29
const [ avatar , setAvatar ] = useState ( "" ) ;
31
30
const [ index , setIndex ] = useState ( Math . floor ( Math . random ( ) * emojiList . length ) ) ;
32
31
@@ -35,7 +34,6 @@ const Join = ({ location }) => {
35
34
// if queries present in url, retrieve them to display
36
35
const { error } = queryString . parse ( location . search ) ;
37
36
const { room } = queryString . parse ( location . search ) ;
38
- setDefaultRoom ( room ) ;
39
37
setRoom ( room ) ;
40
38
const newErrorList = [
41
39
`Username is taken in room ${ room } ` ,
@@ -51,7 +49,6 @@ const Join = ({ location }) => {
51
49
// A function to get a random room name
52
50
async function fetchData ( ) {
53
51
const response = await axios . get ( process . env . REACT_APP_SERVER + "/room" ) ;
54
- setDefaultRoom ( response . data . room ) ;
55
52
setRoom ( response . data . room ) ;
56
53
const newErrorList = [
57
54
`Username is taken in room ${ response . data . room } ` ,
@@ -68,7 +65,7 @@ const Join = ({ location }) => {
68
65
}
69
66
return ;
70
67
// eslint-disable-next-line
71
- } , [ error , location . search ] ) ;
68
+ } , [ location . search ] ) ;
72
69
73
70
// Remove active from carousel and randomise the index
74
71
const handleSetIndex = ( ) => {
@@ -89,6 +86,12 @@ const Join = ({ location }) => {
89
86
pickEmoji ( emojiList [ index ] ) ;
90
87
} , [ index ] ) ;
91
88
89
+ useEffect ( ( ) => {
90
+ if ( name && room && error === "Username and/or room name is empty" ) {
91
+ setError ( "" ) ;
92
+ }
93
+ } , [ room , name , error ] ) ;
94
+
92
95
// Function to get the active emoji and set the avatar
93
96
// Added a time out to allow the carousal to refresh and add active attribute
94
97
const getKey = ( ) => {
@@ -155,6 +158,7 @@ const Join = ({ location }) => {
155
158
placeholder = "Username"
156
159
title = "Type in a name that will be visible to others. Max length is 12 characters :)"
157
160
maxLength = "12"
161
+ value = { name }
158
162
required
159
163
onChange = { ( event ) => setName ( event . target . value . trim ( ) . toLowerCase ( ) ) }
160
164
/>
@@ -167,11 +171,13 @@ const Join = ({ location }) => {
167
171
id = "id_room"
168
172
className = "form-control"
169
173
placeholder = "Room"
170
- defaultValue = { defaultRoom }
174
+ value = { room }
171
175
title = "Type in a room name. Could be one that is already created and you are joining or a brand new room. Max length is 150 characters"
172
176
maxLength = "150"
173
177
required
174
- onChange = { ( event ) => setRoom ( event . target . value . trim ( ) . toLowerCase ( ) ) }
178
+ onChange = { ( event ) => {
179
+ setRoom ( event . target . value . trim ( ) . toLowerCase ( ) ) ;
180
+ } }
175
181
/>
176
182
< label htmlFor = "id_room" > Room:</ label >
177
183
</ div >
0 commit comments