Skip to content

Commit d23e6a1

Browse files
committed
Refractored part of func in ChatRoomListAPI.handleChatRoomListChange, created dummy ChatRoom component files.
1 parent fa271ef commit d23e6a1

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

src/app/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { connect } from 'react-redux';
33
import FrontPage from '../frontpage/FrontPage';
44
import ChatRoomList from './chatroomlist/ChatRoomList';
55
import {initializeConnection} from '../redux/actions/SocketActions';
6+
import { ChatRoom } from './chatroom/ChatRoom';
67

78
class App extends React.Component{
89
componentDidUpdate(){
@@ -23,6 +24,7 @@ class App extends React.Component{
2324
return (
2425
<div>
2526
<ChatRoomList />
27+
<ChatRoom />
2628
</div>
2729
);
2830
}

src/app/chatroom/ChatRoom.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React, { Component } from 'react'
2+
import PropTypes from 'prop-types'
3+
import { connect } from 'react-redux'
4+
5+
export class ChatRoom extends Component {
6+
7+
render() {
8+
return (
9+
<div>
10+
11+
</div>
12+
)
13+
}
14+
}
15+
16+
const mapStateToProps = (state) => ({
17+
18+
})
19+
20+
const mapDispatchToProps = {
21+
22+
}
23+
24+
export default connect(mapStateToProps, mapDispatchToProps)(ChatRoom)

src/app/chatroom/ChatRoomAPI.js

Whitespace-only changes.

src/app/chatroomlist/ChatRoomList.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ class ChatRoomList extends React.Component{
2121
return this.props.chatRooms;
2222
}
2323

24-
render(){
25-
return (
26-
<div>
27-
{this.displayList()}
28-
</div>
29-
);
30-
}
31-
3224
displayList(){
3325
return this.props.chatRooms.map((chatRoom) =>
3426
<div key={chatRoom.id} onClick={() => { this.props.selectChatRoom(chatRoom.id)}}>
3527
{chatRoom.name}
3628
</div>
3729
)
3830
}
31+
32+
render(){
33+
return (
34+
<div>
35+
{this.displayList()}
36+
</div>
37+
);
38+
}
3939
}
4040

4141
ChatRoomList.propTypes = {

src/app/chatroomlist/ChatRoomListAPI.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ export const subscribeChatRoomListTopic = (socketSubscribe, addChatRoom, updateC
99
}
1010

1111
const handleChatRoomListChange = (payload, addChatRoom, updateChatRoom, clientChatRoomList) => {
12-
let chatRoomListJson;
12+
let chatRoomListJson = JSON.parse(payload.body);
1313

14-
if(JSON.parse(payload.body) instanceof Array){
15-
chatRoomListJson = JSON.parse(payload.body);
16-
}else{
17-
chatRoomListJson = [JSON.parse(payload.body)]
14+
if(!(chatRoomListJson instanceof Array)){
15+
chatRoomListJson = [chatRoomListJson];
1816
}
1917

2018
chatRoomListJson.forEach(chatRoom => {

0 commit comments

Comments
 (0)