Skip to content
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

Merged
merged 17 commits into from
Jun 17, 2021
Merged

Improve sockets #10

merged 17 commits into from
Jun 17, 2021

Conversation

sebthtan
Copy link
Owner

  1. Implemented JWT auth for sockets.
  2. Implemented indicator to show when the other user is actively typing.
    • In components/ActiveChat/Input.js, onChange triggers a dispatch for newly made changeTypingStatus thunk
    • changeTypingStatus thunk emits 'typing-status' to socket
    • 'typing-status' event dispatches displayTypingStatus thunk to store typingStatus (boolean) in conversation state
    • typingStatus-dependent conditional rendering of newly made TypingIndicator component

Copy link
Collaborator

@Mayo19 Mayo19 left a 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}>
Copy link
Collaborator

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?

Copy link
Owner Author

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?

Copy link
Collaborator

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.

Comment on lines 26 to 27
this.typing = false
this.timeout = ''
Copy link
Collaborator

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.

Copy link
Owner Author

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.

Comment on lines 2 to 3
conversations.forEach(convo => convo.typingStatus = false)
return conversations
Copy link
Collaborator

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.

Suggested change
conversations.forEach(convo => convo.typingStatus = false)
return conversations
return conversations.map(convo => {
const newConvo = {...convo, typingStatus: false};
return newConvo;
}

Copy link
Owner Author

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
Copy link
Collaborator

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

Copy link
Owner Author

@sebthtan sebthtan Jun 15, 2021

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.

Comment on lines 92 to 98
const newState = [...state]
const targetConvo = newState.find(convo => {
return convo.otherUser.id === sender.id
})
targetConvo.typingStatus = boolean

return newState
Copy link
Collaborator

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.

Copy link
Owner Author

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.

@Mayo19
Copy link
Collaborator

Mayo19 commented Jun 15, 2021

One additional thing we would've liked to see was improving onlineUsers to be more efficient.

@sebthtan sebthtan requested a review from Mayo19 June 16, 2021 05:43
Copy link
Collaborator

@etchao etchao left a 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 🙂

@@ -70,7 +70,7 @@ const Login = (props) => {
className={classes.input}
InputProps={{
endAdornment: (
<InputAdornment component={Link} position="start">
<InputAdornment component={'div'} position="start">
Copy link
Collaborator

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}>
Copy link
Collaborator

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.

client/src/components/ActiveChat/Messages.js Show resolved Hide resolved
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
Copy link
Collaborator

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

server/bin/www Outdated Show resolved Hide resolved
server/onlineUsers.js Show resolved Hide resolved
@sebthtan sebthtan merged commit 3e10d82 into main Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6) Optional goody: Small improvement of your choice
3 participants