-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve sockets #10
Improve sockets #10
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, I really liked your implementation. I just left a few comments regarding naming, modifying redux state and a couple other small things.
Edit: One additional thing we would've liked to see is improving onlineUsers
to be accessed more efficiently.
Let us know on slack when you're ready for a re-review.
@@ -72,7 +70,7 @@ const Login = (props) => { | |||
className={classes.input} | |||
/> | |||
</FormControl> | |||
<FormControl margin='normal' className={classes.full} error={!!formErrorMessage.confirmPassword}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the changes in this file related to this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 75 was extraneous code from when there was still a confirm-password field on signup. I realized (after completing the login and signup redesign) that I had left that line there; even though it's a single line, is it generally best practice to just make that change in the login/signup-redesign branch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, best practice would be to open a new PR to do cleanup like this. If you want to include it in an unrelated PR like you've done here, it's helpful to reviewers to mention it in the PR description. I wouldn't remove it from this PR at this point.
this.typing = false | ||
this.timeout = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should probably be react state variables, like text
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored so that these are now state variables.
conversations.forEach(convo => convo.typingStatus = false) | ||
return conversations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though conversations is just data from the api in this case, we should still follow convention and return a new object instead of mutating it.
conversations.forEach(convo => convo.typingStatus = false) | |
return conversations | |
return conversations.map(convo => { | |
const newConvo = {...convo, typingStatus: false}; | |
return newConvo; | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a fix for this.
server/bin/www
Outdated
socket.on('typing-status', (data) => { | ||
socket.to(data.recipientId).emit('typing-status', { | ||
sender: data.sender, | ||
boolean: data.boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more descriptive name like isTyping
would be preferred over boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Globally renamed boolean
to isTyping
.
const newState = [...state] | ||
const targetConvo = newState.find(convo => { | ||
return convo.otherUser.id === sender.id | ||
}) | ||
targetConvo.typingStatus = boolean | ||
|
||
return newState |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe since [...state]
only creates a shallow clone you're actually mutating the original reference to targetConvo
. One way of avoiding this is doing something similar to the other reducer functions in the file where we map over the state, create a copy of the object and modify the copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a fix for this.
One additional thing we would've liked to see was improving |
…ut in Input.js to state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks like you've addressed the main issues and added a typing status as well, which is great! There's a few more things that could be improved.
After you've addressed everything, you can merge this PR without waiting for another approval 🙂
client/src/Login.js
Outdated
@@ -70,7 +70,7 @@ const Login = (props) => { | |||
className={classes.input} | |||
InputProps={{ | |||
endAdornment: ( | |||
<InputAdornment component={Link} position="start"> | |||
<InputAdornment component={'div'} position="start"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest using Box
here instead of 'div'
- since this project uses Material UI, it'd be better to stick to using Material UI components instead of mixing regular jsx in to keep things consistent.
@@ -72,7 +70,7 @@ const Login = (props) => { | |||
className={classes.input} | |||
/> | |||
</FormControl> | |||
<FormControl margin='normal' className={classes.full} error={!!formErrorMessage.confirmPassword}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, best practice would be to open a new PR to do cleanup like this. If you want to include it in an unrelated PR like you've done here, it's helpful to reviewers to mention it in the PR description. I wouldn't remove it from this PR at this point.
server/bin/www
Outdated
@@ -29,31 +30,63 @@ const server = http.createServer(app); | |||
* Listen on provided port, on all network interfaces, and sync database. | |||
*/ | |||
|
|||
const io = require("socket.io")(server); | |||
// TO-DO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this comment can be removed? Or it needs to be updated with more detail
components/ActiveChat/Input.js
, onChange triggers a dispatch for newly madechangeTypingStatus
thunkchangeTypingStatus
thunk emits'typing-status'
to socket'typing-status'
event dispatchesdisplayTypingStatus
thunk to storetypingStatus
(boolean) inconversation
statetypingStatus
-dependent conditional rendering of newly madeTypingIndicator
component