Skip to content

Commit

Permalink
fix: improve notify item/room item style
Browse files Browse the repository at this point in the history
Signed-off-by: Amir Movahedi <[email protected]>
  • Loading branch information
Qolzam committed May 17, 2021
1 parent 5fa36dc commit 162d0b9
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 62 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,
},
});
}),
);

0 comments on commit 162d0b9

Please sign in to comment.