prva verzija

This commit is contained in:
Hamza Iseric
2018-12-07 01:39:20 +01:00
parent b5ec65d8dd
commit 5dc6c76750
18 changed files with 21453 additions and 0 deletions

45
src/App.js Normal file
View File

@@ -0,0 +1,45 @@
// ./src/App.js
import React, { Component } from 'react'
import UsernameForm from './UsernameForm'
import Chat from './Chat'
class App extends Component {
state = {
currentUsername: null,
currentId: null,
currentScreen: 'usernameForm'
}
onUsernameSubmitted = username => {
fetch('http://localhost:3001/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username })
})
.then(response => response.json())
.then(data => {
this.setState({
currentId: data.id,
currentUsername: data.name,
currentScreen: 'chat'
})
})
.catch(error => {
console.error('error', error)
})
}
render() {
if (this.state.currentScreen === 'usernameForm') {
return <UsernameForm handleSubmit={this.onUsernameSubmitted} />
}
if (this.state.currentScreen === 'chat') {
return <Chat currentId={this.state.currentId} />
}
}
}
export default App;