-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f93b44
commit f0abeb3
Showing
20 changed files
with
639 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export function initializeSession(userId, sessionId, isFollower) { | ||
return { | ||
type: 'INITIALIZE_SESSION', | ||
userId, | ||
sessionId, | ||
isFollower | ||
} | ||
} | ||
|
||
export function userConnected(userId) { | ||
return { | ||
type: 'USER_CONNECTED', | ||
userId | ||
} | ||
} | ||
|
||
export function userDisconnected(userId) { | ||
return { | ||
type: 'USER_DISCONNECTED', | ||
userId | ||
} | ||
} | ||
|
||
export function startSession() { | ||
return { | ||
type: 'START_SESSION' | ||
} | ||
} | ||
|
||
export function setDisplayName(userId, displayName) { | ||
return { | ||
type: 'SET_DISPLAY_NAME', | ||
userId: userId, | ||
displayName: displayName | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,100 @@ | ||
import React, {Component} from 'react' | ||
import PropTypes from 'prop-types' | ||
import { connect } from 'react-redux' | ||
import HomePageComponent from './HomePageComponent'; | ||
import UserListComponent from './user-list/UserListComponent' | ||
import { setDisplayName, startSession } from '../actions' | ||
import MenuComponent from "./menu/MenuComponent"; | ||
import MenuItemComponent from "./menu/MenuItemComponent"; | ||
|
||
class AppComponent extends Component { | ||
|
||
constructor(props) { | ||
super(props) | ||
constructor(props) { | ||
super(props) | ||
this.startSession = this.startSession.bind(this); | ||
|
||
this.startSession = this.startSession.bind(this); | ||
this.state = { | ||
userPanelActive: true | ||
} | ||
} | ||
|
||
render() { | ||
const {sessionId, isFollower, isSessionStarted} = this.props | ||
const {userPanelActive} = this.state | ||
|
||
this.state = { | ||
sessionId: props.sessionId, | ||
isFollower: props.isFollower, | ||
isSessionStarted: false | ||
return ( | ||
<div> | ||
{!isSessionStarted && | ||
<HomePageComponent | ||
userId={this.props.userId} | ||
sessionId={sessionId} | ||
isFollower={isFollower} | ||
onStartSession={(displayName) => this.startSession(displayName)} | ||
/> | ||
} | ||
} | ||
<MenuComponent> | ||
<MenuItemComponent | ||
label={`Users (${this.props.users.length})`} | ||
onItemClicked={() => this.openUserPanel()} | ||
/> | ||
</MenuComponent> | ||
<UserListComponent | ||
users={this.props.users} | ||
active={userPanelActive} | ||
onCloseClicked={() => {this.closeUserPanel()}} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
render() { | ||
const {sessionId, isFollower, isSessionStarted} = this.state | ||
|
||
return ( | ||
<div> | ||
{!isSessionStarted && | ||
<HomePageComponent | ||
sessionId={sessionId} | ||
isFollower={isFollower} | ||
onStartSession={this.startSession} | ||
/> | ||
} | ||
</div> | ||
) | ||
} | ||
startSession(displayName) { | ||
this.props.onStartSession(this.props.userId, displayName) | ||
} | ||
|
||
startSession() { | ||
this.setState(state => ({ | ||
state, | ||
isSessionStarted: true | ||
})) | ||
} | ||
openUserPanel() { | ||
this.setState((state) => ({ | ||
...state, | ||
userPanelActive: true | ||
})) | ||
} | ||
|
||
closeUserPanel() { | ||
this.setState((state) => ({ | ||
...state, | ||
userPanelActive: false | ||
})) | ||
} | ||
} | ||
|
||
AppComponent.propTypes = { | ||
userId: PropTypes.string, | ||
users: PropTypes.arrayOf(PropTypes.shape({ | ||
id: PropTypes.string, | ||
displayName: PropTypes.string | ||
})), | ||
sessionId: PropTypes.string, | ||
isFollower: PropTypes.bool.isRequired, | ||
isSessionStarted: PropTypes.bool, | ||
isFollower: PropTypes.bool, | ||
onStartSession: PropTypes.func.isRequired | ||
} | ||
|
||
const mapStateToProps = (state) => { | ||
return { | ||
userId: state.userId, | ||
sessionId: state.sessionId, | ||
isSessionStarted: state.isSessionStarted, | ||
isFollower: state.isFollower, | ||
users: state.users | ||
} | ||
} | ||
|
||
const mapDispatchToProps = (dispatch) => { | ||
return { | ||
onStartSession: (userId, displayName) => { | ||
dispatch(startSession()) | ||
dispatch(setDisplayName(userId, displayName)) | ||
} | ||
} | ||
} | ||
|
||
export default AppComponent | ||
export default connect(mapStateToProps, mapDispatchToProps)(AppComponent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.