-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from red-gold/bug/1.0/37
Bug/1.0/37
- Loading branch information
Showing
12 changed files
with
119 additions
and
172 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
This file was deleted.
Oops, something went wrong.
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,67 +1,67 @@ | ||
import React from 'react'; | ||
import ListItemText from '@material-ui/core/ListItemText'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import UserAvatar from 'components/userAvatar/UserAvatarComponent'; | ||
import React, { Component } from 'react'; | ||
import classNames from 'classnames'; | ||
import ListItemAvatar from '@material-ui/core/ListItemAvatar'; | ||
import Badge from '@material-ui/core/Badge'; | ||
import Typography from '@material-ui/core/Typography'; | ||
|
||
import useTheme from '@material-ui/core/styles/useTheme'; | ||
import { IRoomItemProps } from './IRoomItemProps'; | ||
import { IRoomItemState } from './IRoomItemState'; | ||
import { roomItemStyles } from './roomItemStyles'; | ||
import { Button } from '@material-ui/core'; | ||
import { useStyles } from './roomItemStyles'; | ||
|
||
export class RoomItemComponent extends Component<IRoomItemProps, IRoomItemState> { | ||
constructor(props: IRoomItemProps) { | ||
super(props); | ||
|
||
// Defaul state | ||
this.state = {}; | ||
|
||
// Binding functions to `this` | ||
this.handleOpenRoom = this.handleOpenRoom.bind(this); | ||
} | ||
export function RoomItemComponent(props: IRoomItemProps) { | ||
const classes = useStyles(); | ||
const theme = useTheme(); | ||
|
||
handleOpenRoom = (event: any) => { | ||
const handleOpenRoom = (event: any) => { | ||
event.preventDefault(); | ||
const { openRoom, room, closeRoomList } = this.props; | ||
const { openRoom, room, closeRoomList } = props; | ||
const roomId: string = room.get('roomId'); | ||
openRoom(roomId); | ||
closeRoomList(); | ||
}; | ||
|
||
render() { | ||
const { avatar, fullName, classes, room } = this.props; | ||
const roomId: string = room.get('objectId'); | ||
const unreadCount: string = room.get('unreadCount'); | ||
const lastMessageText = room.getIn(['lastMessage', 'text'], ''); | ||
return ( | ||
<Button | ||
key={`room-item-${roomId}`} | ||
className={classNames(classes.listItem)} | ||
onClick={this.handleOpenRoom} | ||
fullWidth | ||
component={'a'} | ||
> | ||
<ListItemAvatar> | ||
<UserAvatar fullName={fullName} size={40} fileName={avatar} /> | ||
</ListItemAvatar> | ||
<ListItemText | ||
className={classes.itemText} | ||
primary={fullName} | ||
secondary={ | ||
<Typography variant="body2" noWrap> | ||
{lastMessageText} | ||
</Typography> | ||
} | ||
/> | ||
const { avatar, fullName, room } = props; | ||
const roomId: string = room.get('objectId'); | ||
const unreadCount: string = room.get('unreadCount'); | ||
const lastMessageText = room.getIn(['lastMessage', 'text'], ''); | ||
return ( | ||
<Button | ||
key={`room-item-${roomId}`} | ||
className={classNames(classes.listItem)} | ||
onClick={handleOpenRoom} | ||
fullWidth | ||
component={'a'} | ||
> | ||
<ListItemAvatar> | ||
<UserAvatar fullName={fullName} size={40} fileName={avatar} /> | ||
</ListItemAvatar> | ||
<ListItemText | ||
className={classes.itemText} | ||
primary={ | ||
<Typography | ||
sx={{ textTransform: 'capitalize', color: theme.palette.text.primary }} | ||
variant="subtitle1" | ||
noWrap | ||
> | ||
{fullName} | ||
</Typography> | ||
} | ||
secondary={ | ||
<Typography | ||
sx={{ textTransform: 'none', color: theme.palette.text.secondary }} | ||
variant="body2" | ||
noWrap | ||
> | ||
{lastMessageText} | ||
</Typography> | ||
} | ||
/> | ||
|
||
<Badge badgeContent={unreadCount} color="secondary"></Badge> | ||
</Button> | ||
); | ||
} | ||
<Badge badgeContent={unreadCount} color="secondary"></Badge> | ||
</Button> | ||
); | ||
} | ||
|
||
// - Connect component to redux store | ||
export default withStyles(roomItemStyles)(RoomItemComponent); | ||
export default RoomItemComponent; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,76 +1,38 @@ | ||
|
||
import withStyles from '@material-ui/core/styles/withStyles'; | ||
import { Map } from 'immutable'; | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import React from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import PostComponent from 'components/post'; | ||
import * as postActions from 'store/actions/postActions'; | ||
import * as userActions from 'store/actions/userActions'; | ||
|
||
import { IPostPageProps } from './IPostPageProps'; | ||
import { IPostPageState } from './IPostPageState'; | ||
import { postPageStyles } from './postPageStyles'; | ||
|
||
export class PostPageComponent extends Component<IPostPageProps, IPostPageState> { | ||
static propTypes = {}; | ||
|
||
constructor(props: IPostPageProps) { | ||
super(props); | ||
|
||
// Defaul state | ||
this.state = {}; | ||
|
||
// Binding functions to `this` | ||
} | ||
componentDidMount() { | ||
const { loadPost, loadUserInfo } = this.props; | ||
if (loadPost && loadUserInfo) { | ||
loadPost(); | ||
loadUserInfo(); | ||
} | ||
} | ||
|
||
render() { | ||
const { classes, post, userInfo } = this.props; | ||
if (!userInfo || !post) { | ||
return <div />; | ||
} | ||
return ( | ||
<div className={classes.container}> | ||
<div className={classes.postBox} key={`post-stream-column-${userInfo.userId}`}> | ||
<PostComponent key={`${post.get('id')}-stream-div-post`} post={post} /> | ||
</div> | ||
import { useParams } from 'react-router'; | ||
import { userSelector } from 'store/reducers/users/userSelector'; | ||
import { postSelector } from 'store/reducers/posts/postSelector'; | ||
import { useStyles } from './postPageStyles'; | ||
|
||
const selectUserProfileById = userSelector.selectUserProfileById(); | ||
const selectPost = postSelector.selectPost(); | ||
|
||
export function PostPageComponent() { | ||
const { userId, postId } = useParams(); | ||
const classes = useStyles(); | ||
// Dispatcher | ||
const dispatch = useDispatch(); | ||
const loadPost = () => dispatch(postActions.dbGetPostById(userId, postId)); | ||
|
||
// Selector | ||
const userInfo = useSelector((state: Map<string, any>) => selectUserProfileById(state, { userId })); | ||
const post = useSelector((state: Map<string, any>) => selectPost(state, { postId })); | ||
|
||
React.useEffect(() => { | ||
loadPost(); | ||
}); | ||
|
||
return ( | ||
<div className={classes.container}> | ||
<div className={classes.postBox} key={`post-stream-column-${userInfo.get('userId', '')}`}> | ||
<PostComponent key={`${post.get('id')}-stream-div-post`} post={post} /> | ||
</div> | ||
); | ||
} | ||
</div> | ||
); | ||
} | ||
|
||
/** | ||
* Map dispatch to props | ||
*/ | ||
const mapDispatchToProps = (dispatch: any, ownProps: IPostPageProps) => { | ||
const { userId, postId } = ownProps.match.params; | ||
return { | ||
loadPost: () => dispatch(postActions.dbGetPostById(userId, postId)), | ||
loadUserInfo: () => dispatch(userActions.dbGetUserInfoByUserId(userId)), | ||
}; | ||
}; | ||
|
||
/** | ||
* Map state to props | ||
*/ | ||
const mapStateToProps = (state: Map<string, any>, ownProps: IPostPageProps) => { | ||
const { userId, postId } = ownProps.match.params; | ||
const userInfo: Map<string, any> = state.getIn(['state', 'user', 'entities', userId], Map({})); | ||
const post: Map<string, any> = state.getIn(['post', 'entities', postId], Map({})); | ||
return { | ||
userInfo: userInfo.toJS(), | ||
post, | ||
}; | ||
}; | ||
|
||
// - Connect component to redux store | ||
export default connect<{}, {}, any, any>( | ||
mapStateToProps, | ||
mapDispatchToProps, | ||
)(withStyles(postPageStyles as any)(PostPageComponent as any) as any); | ||
export default PostPageComponent; |
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.