Skip to content

Commit

Permalink
[#370] added pressing Enter to create a room (#384)
Browse files Browse the repository at this point in the history
* [#370] added pressing Enter to create a room

* [#370] handlers renamed and moved room name check
  • Loading branch information
2or4spaces authored Jul 28, 2023
1 parent fc21585 commit 23d6bf0
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,31 @@ export const CreateRoomContainer = () => {
[setName],
)

const handleCreateRoomClick = useCallback(() => {
const roomName = name.trim()
dispatch(createRoomAction({ name: roomName, config: { dndEnabled: true } }))
}, [dispatch, name])
const handleCreateRoom = useCallback(() => {
if (name.trim() !== '' && !validationErrors) {
dispatch(createRoomAction({ name, config: { dndEnabled: true } }))
}
}, [name, validationErrors, dispatch])

const handleCreateRoomKeyDown = useCallback<React.KeyboardEventHandler<HTMLInputElement>>(
e => {
if (e.key === 'Enter') {
handleCreateRoom()
}
},
[handleCreateRoom],
)

return (
<InputWithButton>
<InputWithButton.Input inputProps={{ 'data-test-id': 'CreateGameInput' }} placeholder="Room name..." onChange={handleNameChange} />
<InputWithButton.Input
inputProps={{ 'data-test-id': 'CreateGameInput' }}
placeholder="Room name..."
onChange={handleNameChange}
onKeyDown={handleCreateRoomKeyDown}
/>
<InputWithButton.ButtonWrapper>
<InputWithButton.Button
data-test-id="CreateGameButton"
onClick={handleCreateRoomClick}
disabled={!name || !!validationErrors}
variant="contained"
>
<InputWithButton.Button data-test-id="CreateGameButton" onClick={handleCreateRoom} disabled={!name || !!validationErrors} variant="contained">
<Typography fontSize="inherit">Create</Typography>
</InputWithButton.Button>
</InputWithButton.ButtonWrapper>
Expand Down

1 comment on commit 23d6bf0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for apps/ligretto-gameplay-backend

St.
Category Percentage Covered / Total
🔴 Statements 48.63% 373/767
🔴 Branches 24.53% 26/106
🔴 Functions 26.07% 55/211
🔴 Lines 46.27% 310/670

Test suite run success

12 tests passing in 1 suite.

Report generated by 🧪jest coverage report action from 23d6bf0

Please sign in to comment.