Skip to content

Commit

Permalink
get user email
Browse files Browse the repository at this point in the history
  • Loading branch information
corscheparrera committed Jun 21, 2018
1 parent a314a3b commit 7a24c9a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
21 changes: 17 additions & 4 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class App extends Component {
constructor(props) {
super(props);
this.state = {
chatId: ""
chatId: "",
email: ""
};
}

Expand All @@ -23,22 +24,34 @@ class App extends Component {
this.setState({ chatId: `allChat/chat${id}` });
};

getUserEmail = data => {
this.setState({ email: data });
};
render() {
return (
<Grid>
<Row>
<h1
style={{
textAlign: "center",
paddingBottom: 30
textAlign: "center"
}}
>
Chat Room
</h1>
</Row>
<Row>
<h4
style={{
textAlign: "center",
paddingBottom: 30
}}
>
Client: {this.state.email}
</h4>
</Row>
<Row>
<Col sm={12}>
<Chat path={this.state.chatId} />
<Chat path={this.state.chatId} getUserEmail={this.getUserEmail} />
</Col>
</Row>
</Grid>
Expand Down
6 changes: 5 additions & 1 deletion src/components/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, { Component } from "react";
import ChatInput from "./ChatInput";
import Messages from "./Messages";
import fire from "./Firebase.js";
import firebase from "firebase";

const database = fire.database();
const avocat = {
Expand Down Expand Up @@ -36,6 +35,11 @@ export default class Chat extends Component {
database
.ref(`${this.props.path}`)
.on("child_added", x => this.updateState(x.val()));
database.ref(`${this.props.path}`).once("value", result => {
let email = result.val()[Object.keys(result.val())[0]].user.email;
console.log(email);
this.props.getUserEmail(email);
});
}

updateState = data => {
Expand Down

0 comments on commit 7a24c9a

Please sign in to comment.