Skip to content

Commit e9ea4c8

Browse files
committed
I have added last message
1 parent 3a89a52 commit e9ea4c8

File tree

10 files changed

+91
-41
lines changed

10 files changed

+91
-41
lines changed

__tests__/reducers/ChatReducer.test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('testing chat reducers', () => {
1717
allusers: [],
1818
error: '',
1919
pending: false,
20+
lastchat: {}
2021
}
2122
)
2223
})
@@ -39,6 +40,7 @@ describe('testing chat reducers', () => {
3940
allusers: [],
4041
error: '',
4142
pending: false,
43+
lastchat: {}
4244
})
4345
})
4446

@@ -59,6 +61,7 @@ describe('testing chat reducers', () => {
5961
allusers: { data: { profile: {} }, status: 200 },
6062
error: '',
6163
pending: false,
64+
lastchat: {}
6265
})
6366
})
6467

@@ -79,6 +82,7 @@ describe('testing chat reducers', () => {
7982
allusers: [],
8083
error: '',
8184
pending: false,
85+
lastchat: {}
8286
})
8387
})
8488

@@ -99,6 +103,7 @@ describe('testing chat reducers', () => {
99103
allusers: [],
100104
error: '',
101105
pending: false,
106+
lastchat: {}
102107
})
103108
})
104109

@@ -119,6 +124,7 @@ describe('testing chat reducers', () => {
119124
allusers: [],
120125
error: '',
121126
pending: false,
127+
lastchat: {}
122128
})
123129
})
124130

@@ -139,6 +145,7 @@ describe('testing chat reducers', () => {
139145
allusers: [],
140146
error: '',
141147
pending: false,
148+
lastchat: {}
142149
})
143150
})
144151

@@ -159,6 +166,7 @@ describe('testing chat reducers', () => {
159166
allusers: [],
160167
error: '',
161168
pending: false,
169+
lastchat: {}
162170
})
163171
})
164172

@@ -179,6 +187,7 @@ describe('testing chat reducers', () => {
179187
allusers: [],
180188
error: '',
181189
pending: false,
190+
lastchat: {}
182191
})
183192
})
184193

@@ -198,7 +207,8 @@ describe('testing chat reducers', () => {
198207
supportresponse: [],
199208
pending: false,
200209
allusers: [],
201-
error: ''
210+
error: '',
211+
lastchat: {}
202212
})
203213
})
204214
})

src/components/Chat/ChatMessages.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@ function Alert(props) {
1818
function ChatMessages(props){
1919
const [open, setOpen] = React.useState(false)
2020
const [error, setError] = React.useState('')
21-
const theerror = props.error;
21+
const {theerror , chats, pending}= props;
22+
const vMessages = props.vmessages
2223
React.useEffect(()=>{
2324
props.getChats();
2425
props.getVisitorsMessages()
2526
io.on('new_message', data =>{
2627
props.getChats();
27-
console.log('User message', data)
2828
})
2929
io.on('support_message', data=>{
3030
props.getVisitorsMessages()
31-
console.log("Visitor's messages",data)
3231
})
3332

3433

@@ -39,35 +38,29 @@ function ChatMessages(props){
3938

4039
}, [])
4140

42-
43-
const chats = props.chats;
4441
const user = localStorage.getItem('userName')
45-
const vMessages = props.vmessages;
46-
const pending = props.pending;
47-
48-
49-
5042

5143
const handleClose = () => {
5244

5345
setOpen(false);
5446
};
55-
5647
return (
5748
<React.Fragment>
5849
<CssBaseline />
5950
{error && <Snackbar open={open} autoHideDuration={7000} onClose={handleClose}>
6051
<Alert onClose={handleClose} severity="error">
6152
{error}
6253
</Alert>
54+
6355
</Snackbar>}
56+
6457
{pending === true ? <LinearProgress/> : <Paper square container="true">
6558

6659
<Paper>
6760
<Toolbar>
6861
<List>
6962
<ListItem>
70-
<ListItemAvatar><Avatar alt="Profile Picture" src="" /></ListItemAvatar>
63+
<ListItemAvatar><Avatar alt="Profile Picture" src={localStorage.getItem('pp')} /></ListItemAvatar>
7164
<ListItemText primary={user} secondary="User"/>
7265
</ListItem>
7366
</List>

src/components/Chat/ChatStyles.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,12 @@ export const useStyles = makeStyles((theme) => ({
131131
},
132132
media: {
133133
height: 140
134+
},
135+
clicked: {
136+
color: '#376C7C',
137+
fontWeight: 'bold'
138+
},
139+
notclicked: {
140+
color: 'inherit'
134141
}
135142
}));

src/components/Chat/ChatUsers.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { TextField, Typography, CssBaseline, AppBar, makeStyles, Toolbar, IconButton, Fab, ListItem, ListItemAvatar, ListItemText, ListSubheader, Avatar, Paper, List, Snackbar } from "@material-ui/core";
33
import { Person } from "@material-ui/icons";
44
import { connect } from 'react-redux';
5-
import { fetchUsersChat,fetchUsers, getVisitorsList } from '../../redux/actions/ChatAction';
5+
import { fetchUsersChat,fetchUsers, getVisitorsList, getLastMessage } from '../../redux/actions/ChatAction';
66
import UsersList from './Lists/UsersList';
77
import VisitorsListing from './vList';
88
import LinearProgress from '@material-ui/core/LinearProgress';
@@ -16,10 +16,14 @@ function ChatUsers(props) {
1616
const theerror = props.error;
1717
const [open, setOpen] = React.useState(false)
1818
const [error, setError] = React.useState('')
19+
const lastchat = props.lastmessage
20+
21+
console.log('lastmessage', lastchat)
1922
React.useEffect(()=>{
2023
props.fetchUsersChat();
2124
props.getVisitorsList();
2225
props.fetchUsers();
26+
props.getLastMessage()
2327
if(theerror){
2428
setError(theerror)
2529
setOpen(true)
@@ -35,7 +39,6 @@ function ChatUsers(props) {
3539
setOpen(false);
3640
};
3741

38-
3942
return (
4043
<div>
4144
<CssBaseline/>
@@ -52,9 +55,9 @@ function ChatUsers(props) {
5255
variant="filled"
5356
style={{boxSizing: "border-box",width: '100%', padding: '10px', borderRadius: '50px'}}
5457
><Person/></TextField>
55-
<UsersList users={users} allusers={allusers}/>
58+
<UsersList users={users} allusers={allusers} lastchat={lastchat} />
5659
{visitors && <div>
57-
<VisitorsListing visitors={visitors}/>
60+
<VisitorsListing visitors={visitors} />
5861
</div>}
5962
</Paper>}
6063
</div>
@@ -68,7 +71,8 @@ const mapStateToProps = (state) => ({
6871
allusers: state.chat.allusers,
6972
error: state.chat.error,
7073
pending: state.chat.pending,
71-
error: state.chat.error
74+
error: state.chat.error,
75+
lastmessage: state.chat.lastchat
7276
})
7377

74-
export default connect(mapStateToProps, { fetchUsersChat, getVisitorsList, fetchUsers })(ChatUsers)
78+
export default connect(mapStateToProps, { fetchUsersChat, getVisitorsList, fetchUsers, getLastMessage })(ChatUsers)

src/components/Chat/Lists/NewMessage.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
22
import axios from 'axios';
33
import { Paper, Toolbar, Input, InputAdornment, IconButton, FormHelperText, CircularProgress, FormControl } from '@material-ui/core';
44
import { connect } from 'react-redux';
5-
import { newMessageAction, supportResponds, getChats, getVisitorsMessages } from '../../../redux/actions/ChatAction'
5+
import { newMessageAction, supportResponds, getChats, getVisitorsMessages, getLastMessage } from '../../../redux/actions/ChatAction'
66
import SendIcon from '@material-ui/icons/Send';
77
import AttachFileIcon from '@material-ui/icons/AttachFile';
88
import {Link} from 'react-router-dom';
@@ -21,7 +21,6 @@ function NewMessage(props) {
2121
React.useEffect(() => {
2222
io.on('connection', socket=>{
2323
socket.emit('send_message',visitorResponse)
24-
console.log(visitorResponse)
2524
})
2625
})
2726

@@ -41,6 +40,7 @@ function NewMessage(props) {
4140
setMessage('')
4241
setFeedbackText("Message sent!")
4342
props.getChats()
43+
props.getLastMessage()
4444
});
4545

4646
io.emit('connection', socket=>{
@@ -57,6 +57,7 @@ function NewMessage(props) {
5757
setMessage('')
5858
setFeedbackText("Image sent!")
5959
props.getChats()
60+
props.getLastMessage()
6061
});
6162
io.emit('send_message', messageData)
6263
}else{
@@ -188,4 +189,4 @@ function NewMessage(props) {
188189
)
189190
}
190191

191-
export default connect(null, { newMessageAction, supportResponds, getChats, getVisitorsMessages })(NewMessage);
192+
export default connect(null, { newMessageAction, supportResponds, getChats, getVisitorsMessages,getLastMessage })(NewMessage);

src/components/Chat/Lists/UsersList.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function UsersList(props) {
77

88
const users = props.users;
99
const allusers = props.allusers;
10+
const lastchat = props.lastchat
1011

1112
const classes = useStyles();
1213
return (
@@ -16,14 +17,16 @@ function UsersList(props) {
1617
<div key={user.id} onClick={()=> {
1718
localStorage.setItem('userId', user.id),
1819
localStorage.setItem('userName', user.first_name)
20+
localStorage.setItem('pp', user.profile_picture)
1921
localStorage.removeItem('visit')
22+
2023
}}>
2124
<a href='' style={{textDecoration: 'none', color: 'inherit'}}>
2225
<ListItem button>
2326
<ListItemAvatar>
2427
<Avatar alt={user.first_name} src={user.profile_picture} />
2528
</ListItemAvatar>
26-
<ListItemText primary={user.first_name} secondary={user.last_name} />
29+
<ListItemText primary={user.first_name} secondary={localStorage.getItem('userId')===user.id ? lastchat.message : "Start a chat"} className={localStorage.getItem('userId')===user.id ? classes.clicked : classes.notclicked}/>
2730
</ListItem>
2831
</a>
2932
</div>
@@ -34,13 +37,14 @@ function UsersList(props) {
3437
localStorage.setItem('userId', user.id),
3538
localStorage.setItem('userName', user.first_name)
3639
localStorage.removeItem('visit')
40+
3741
}}>
3842
<a href='' style={{textDecoration: 'none', color: 'inherit'}}>
3943
<ListItem button>
4044
<ListItemAvatar>
4145
<Avatar alt={user.first_name} src={user.profile_picture} />
4246
</ListItemAvatar>
43-
<ListItemText primary={user.first_name} secondary={user.last_name} />
47+
<ListItemText primary={user.first_name} secondary="Click to chat" />
4448
</ListItem>
4549
</a>
4650
</div>))}

src/components/Chat/Visitors/NewForm.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function NewForm(props){
2222
React.useEffect(()=>{
2323
io.emit('connection', socket=> {
2424
socket.on('support_message', data => {
25-
console.log(data)
2625
props.getSupportResponse();
2726
})
2827
})

0 commit comments

Comments
 (0)