Skip to content

Commit

Permalink
Merge pull request #42 from red-gold/bug/1.0/37
Browse files Browse the repository at this point in the history
Bug/1.0/37
  • Loading branch information
Qolzam authored May 17, 2021
2 parents 98ad4e6 + 162d0b9 commit f109c42
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 172 deletions.
5 changes: 5 additions & 0 deletions src/api/StringAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ const getNumberOfLines = (input: string) => {
return input.split('\n').length;
};

function capitalizeFirstLetter(input: string) {
return input.charAt(0).toUpperCase() + input.slice(1);
}

export default {
isValidEmail,
queryString,
Expand All @@ -81,4 +85,5 @@ export default {
validateUrl,
getNumberOfLines,
isEmpty,
capitalizeFirstLetter,
};
24 changes: 20 additions & 4 deletions src/components/notifyItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import classNames from 'classnames';
import ListItemAvatar from '@material-ui/core/ListItemAvatar';

import { INotifyItemProps } from './INotifyItemProps';
import { Button } from '@material-ui/core';
import Button from '@material-ui/core/Button';
import useTheme from '@material-ui/core/styles/useTheme';
import { useStyles } from './notifyItemStyles';
import Typography from '@material-ui/core/Typography';
import { useNavigate } from 'react-router';
import StringAPI from 'api/StringAPI';

export function NotifyItemComponent(props: INotifyItemProps) {
const classes = useStyles();
const navigate = useNavigate();
const theme = useTheme();

const { description, fullName, avatar, isSeen, id, notifierUserId, url, deleteNotify } = props;
const handleSeenNotify = (event: any) => {
event.preventDefault();
Expand Down Expand Up @@ -50,10 +54,22 @@ export function NotifyItemComponent(props: INotifyItemProps) {
</ListItemAvatar>
<ListItemText
className={classes.itemText}
primary={fullName}
primary={
<Typography
sx={{ textTransform: 'capitalize', color: theme.palette.text.primary }}
variant="subtitle1"
noWrap
>
{fullName}
</Typography>
}
secondary={
<Typography variant="body2" noWrap>
{description}
<Typography
sx={{ textTransform: 'none', color: theme.palette.text.secondary }}
variant="body2"
noWrap
>
{StringAPI.capitalizeFirstLetter(description)}
</Typography>
}
/>
Expand Down
5 changes: 0 additions & 5 deletions src/components/roomItem/IRoomItemProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@ export interface IRoomItemProps {
closeRoomList: () => void;

openRoom: (roomId: string) => any;

/**
* Material ui styles
*/
classes?: any;
}
1 change: 0 additions & 1 deletion src/components/roomItem/IRoomItemState.ts

This file was deleted.

96 changes: 48 additions & 48 deletions src/components/roomItem/index.tsx
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;
8 changes: 4 additions & 4 deletions src/components/roomItem/roomItemStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT

import { Theme } from '@material-ui/core';
import { makeStyles, Theme } from '@material-ui/core';
import { createStyles } from '@material-ui/styles';

export const roomItemStyles = (theme: Theme) =>
export const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
width: '100%',
Expand All @@ -27,7 +27,6 @@ export const roomItemStyles = (theme: Theme) =>
},
listItem: {
padding: '12px 20px !important',
'text-transform': 'none !important',
'&::not(:last-child)': {
marginBottom: 1,
},
Expand Down Expand Up @@ -55,4 +54,5 @@ export const roomItemStyles = (theme: Theme) =>
marginLeft: 10,
color: theme.palette.common.black,
},
});
}),
);
34 changes: 0 additions & 34 deletions src/containers/postPage/IPostPageProps.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/containers/postPage/IPostPageState.ts

This file was deleted.

102 changes: 32 additions & 70 deletions src/containers/postPage/index.tsx
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;
7 changes: 4 additions & 3 deletions src/containers/postPage/postPageStyles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-useless-computed-key */
export const postPageStyles = (theme: any) => ({
import { makeStyles, Theme } from '@material-ui/core/styles';

export const useStyles = makeStyles((theme: Theme) => ({
root: {
position: 'relative',
},
Expand Down Expand Up @@ -54,4 +55,4 @@ export const postPageStyles = (theme: any) => ({
width: '100%',
},
},
});
}));
4 changes: 4 additions & 0 deletions src/routes/HomeRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export const homeRoutes = [
path: '/:userId/posts/:postId/:tag?',
element: <AsyncPostPage />,
},
{
path: '/:userId/posts/:postId',
element: <AsyncPostPage />,
},
{
path: '/search/post',
element: <AsyncSearchPost />,
Expand Down
Loading

0 comments on commit f109c42

Please sign in to comment.