質問編集履歴
2
←をつけているところです
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,116 +14,116 @@
|
|
14
14
|
|
15
15
|
class Chat extends React.Component {
|
16
16
|
|
17
|
-
|
17
|
+
componentDidMount() {
|
18
18
|
|
19
|
-
|
19
|
+
console.log("didmount")
|
20
20
|
|
21
|
-
|
21
|
+
this.props.forRenderSetter();
|
22
22
|
|
23
|
-
|
23
|
+
}
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
|
27
|
+
logMaker = (nowRoomNum) => {
|
28
28
|
|
29
|
-
|
29
|
+
const database = firebase.database();
|
30
30
|
|
31
|
-
|
31
|
+
const ChatLog = database.ref(nowRoomNum);
|
32
32
|
|
33
|
-
|
33
|
+
let Log = [];
|
34
34
|
|
35
|
-
|
35
|
+
ChatLog.on("value", (snapshot) => {
|
36
36
|
|
37
|
-
|
37
|
+
snapshot.forEach((children) => {
|
38
38
|
|
39
|
-
|
39
|
+
let ob = { user: children.val().user, message: children.val().message, photo: children.val().photo }
|
40
40
|
|
41
|
-
|
41
|
+
Log.push(ob)
|
42
42
|
|
43
|
-
|
43
|
+
})
|
44
44
|
|
45
|
-
|
45
|
+
})
|
46
46
|
|
47
|
-
|
47
|
+
return Log;
|
48
48
|
|
49
|
-
|
49
|
+
}
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
-
|
53
|
+
render() {
|
54
54
|
|
55
|
-
|
55
|
+
console.log(this.props.nowRoomNum);
|
56
56
|
|
57
|
-
|
57
|
+
let nowRoomNum = this.props.nowRoomNum;
|
58
58
|
|
59
|
-
|
59
|
+
const currentUser = firebase.auth().currentUser;
|
60
60
|
|
61
|
-
|
61
|
+
const database = firebase.database();
|
62
62
|
|
63
|
-
|
63
|
+
let selectedRoomNum;
|
64
64
|
|
65
|
-
|
65
|
+
let Log = this.logMaker(nowRoomNum);
|
66
66
|
|
67
|
-
|
67
|
+
console.log(Log);
|
68
68
|
|
69
69
|
|
70
70
|
|
71
|
-
return
|
71
|
+
return ( ←ひとつ目のreturn
|
72
72
|
|
73
73
|
|
74
74
|
|
75
|
-
|
75
|
+
< div className="chatPage" >
|
76
76
|
|
77
|
-
|
77
|
+
{console.log("returnが呼ばれます")}
|
78
78
|
|
79
|
-
|
79
|
+
<div className="userNamePosition"><a className="userName">User:{this.props.user}</a></div>
|
80
80
|
|
81
|
-
|
81
|
+
<input type="text" className="chatText" onChange={(e) => this.props.handleMessage(e)} value={this.props.message} placeholder="Message" />
|
82
82
|
|
83
|
-
|
83
|
+
<input type="button" className="chatButton" onClick={() => this.props.addEventListener(nowRoomNum)} value="send" />
|
84
84
|
|
85
|
-
|
85
|
+
<input type="button" className="chatLogout" onClick={() => this.props.logout()} value="logout" />
|
86
86
|
|
87
|
-
|
87
|
+
<input type="button" className="chatBack" onClick={() => this.props.chatBack()} value="back" />
|
88
88
|
|
89
|
-
|
89
|
+
<div className="chatDisplayArea">
|
90
90
|
|
91
|
-
|
91
|
+
{Log.map((chat, index) => {
|
92
92
|
|
93
|
-
|
93
|
+
{ console.log("returnが呼ばれません") }
|
94
94
|
|
95
|
-
|
95
|
+
return ( ←二つ目のreturn
|
96
96
|
|
97
|
-
|
97
|
+
(chat.user == currentUser.displayName) ? (<div className="currentUser"><div className="userPhotoPosition"><img src={chat.photo} className="userPhoto" /></div>
|
98
98
|
|
99
|
-
|
99
|
+
<div className="currentUserMessagePosition"><p className="currentUserMessage">{chat.message}</p></div>
|
100
100
|
|
101
|
-
|
101
|
+
<div className="currentUserNamePosition"><p className="currentUserName">{chat.user}</p></div></div>)
|
102
102
|
|
103
|
-
|
103
|
+
: (<div className="others"><div className="othersPhotoPosition"><img src={chat.photo} className="othersPhoto" /></div>
|
104
104
|
|
105
|
-
|
105
|
+
<div className="othersMessagePosition"><p className="othersMessage">{chat.message}</p></div>
|
106
106
|
|
107
|
-
|
107
|
+
<div className="othersNamePosition"><p className="othersName">{chat.user}</p></div></div>)
|
108
108
|
|
109
|
-
|
109
|
+
)
|
110
110
|
|
111
|
-
|
111
|
+
})
|
112
112
|
|
113
|
-
|
113
|
+
})
|
114
114
|
|
115
|
-
|
115
|
+
})}
|
116
116
|
|
117
|
-
|
117
|
+
</div>
|
118
118
|
|
119
|
-
|
119
|
+
</div >
|
120
120
|
|
121
|
-
|
121
|
+
)
|
122
|
-
|
123
|
-
}
|
124
122
|
|
125
123
|
}
|
126
124
|
|
125
|
+
}
|
126
|
+
|
127
|
-
export default Chat0.
|
127
|
+
export default Chat0.
|
128
128
|
|
129
129
|
```
|
1
firebaseタグ追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|