Skip to content

Commit

Permalink
Merge pull request #154 from chingu-voyages/fix--update-original-thre…
Browse files Browse the repository at this point in the history
…ad-in-threadwindow

Fix  update original thread in threadwindow
  • Loading branch information
rusye committed Mar 16, 2020
2 parents 205a78c + 48f519b commit 0e305ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
22 changes: 22 additions & 0 deletions client/src/components/main/chatwindow/ChatWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ const ChatWindow = props => {
}
}, [socket, threadWindow, threadinfo.id]);

useEffect(() => {
socket.on('updateUser', data => {
if (threadinfo.user_id === data.id) {
if (data.name) {
setThreadInfo(prev => {
return { ...prev, name: data.name };
});

if (data.userImage) {
setThreadInfo(prev => {
return { ...prev, userImage: data.userImage };
});
} else if (data.userImage === null) {
setThreadInfo(prev => {
return { ...prev, userImage: data.userImage };
});
}
}
}
});
}, [socket, threadinfo.user_id]);

return (
<ChatContext.Provider value={{ chatState, dispatch }}>
<Container>
Expand Down
20 changes: 0 additions & 20 deletions client/src/components/main/sidebar/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,6 @@ function Sidebar(props) {
const [currentChannelID, setCurrentChannelID] = useState();
let errorMessage = useContext(MessageContext);

const getChannels = async () => {
setIsLoading(true);

if (localStorage.loggedIn) {
try {
const result = await axios('/api/channels', {
headers: { authorization: `bearer ${localStorage.authToken}` },
});
setAllChannels(result.data);
setIsLoading(false);
return result.data;
} catch (error) {
localStorage.clear();
setIsLoading(false);
errorMessage.set_message([{ msg: 'Unable to get channels.' }]);
setIsError(true);
}
}
};

useEffect(() => {
const getChannels = async () => {
setIsLoading(true);
Expand Down

0 comments on commit 0e305ed

Please sign in to comment.