-
Notifications
You must be signed in to change notification settings - Fork 0
work in progress #15
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
base: master
Are you sure you want to change the base?
work in progress #15
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,5 +18,8 @@ | |
| "devDependencies": { | ||
| "concurrently": "^4.0.1", | ||
| "recursive-install": "^1.4.0" | ||
| }, | ||
| "dependencies": { | ||
| "react-chat-ui": "^0.3.2" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hierarchy of this repo is kind of difficult. So:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed!
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may need to run |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,9 @@ import React, { Component } from 'react'; | |
| import logo from './logo.svg'; | ||
| import './App.css'; | ||
| import Socket from './socket' | ||
| import {Conversation, Message, Sender} from './message' | ||
| import {Conversation, Msg, Sender} from './message' | ||
| import { ChatFeed, Message } from 'react-chat-ui'; | ||
|
|
||
|
|
||
| class App extends Component { | ||
| socket = new Socket(document.location.pathname.replace('/', '')) | ||
|
|
@@ -22,23 +24,25 @@ class App extends Component { | |
| } | ||
| } | ||
| onKeyPress = event => { | ||
| if (event.key === ' ') { | ||
| if (this.state.text === ' ') { | ||
| this.setState({text: ''}); | ||
| } else { | ||
| this.handleSubmit(); | ||
| } | ||
| } | ||
| // if (event.key === ' ') { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the plan to re-add the commented out code?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to talk about the userflow and UX, as mentioned below. do we want each word occupy one bubble, and as user type each word, more bubbles will pop out?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this answer: https://github.com/imann24/now/pull/15/files#r315968692 ?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Planning to remove this code? |
||
| // if (this.state.text === ' ') { | ||
| // this.setState({text: ''}); | ||
| // } else { | ||
| // this.handleSubmit(); | ||
| // } | ||
| // } | ||
| this.handleSubmit(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May want to re-consider this spec in future? Sending a message through the socket on every letter typed may cause some issues (too much network traffic)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, whats your thoughts on this? My impression was that, as was described, user can see each letters being typed/deleted in real-time. also, i found that instead of using onKeyPress props we could use onKeyDown to trigger handleSubmit() even while user pressed backspace/shift/ctrl key.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. regarding network throughput, is there anyway we could make that work? how much traffic could websocket handle?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I like realtime if it's possible. Would probably have to load test to know. Want to write us some automated tests? 😅 Let's keep it live for now. We can switch it back to sending every word if we run into performance issues |
||
| } | ||
| handleSubmit = async e => { | ||
| if (e) { | ||
| e.preventDefault(); | ||
| } | ||
| let newMessage = new Message(this.state.user, this.state.text) | ||
| this.setState(previousState => ({ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Believe we still need a call to update the React state
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. which state should we update in handleSubmit?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| text: "", | ||
| conversation: previousState.conversation.addMessage(newMessage), | ||
| })); | ||
| // alert(this.state.text) | ||
| let newMessage = new Msg(this.state.user, this.state.text) | ||
| // this.setState(previousState => ({ | ||
| // text: "", | ||
| // conversation: previousState.conversation.addMessage(newMessage), | ||
| // })); | ||
| this.socket.sendMessage(newMessage); | ||
| }; | ||
| render() { | ||
|
|
@@ -47,6 +51,8 @@ class App extends Component { | |
| <header className="App-header"> | ||
| <img src={logo} className="App-logo" alt="logo" /> | ||
| </header> | ||
|
|
||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice spacing for visual clarity! |
||
| <form onSubmit={this.handleSubmit}> | ||
| <p> | ||
| <strong>Say Something, {this.state.user.name}:</strong> | ||
|
|
@@ -55,12 +61,17 @@ class App extends Component { | |
| type="text" | ||
| value={this.state.text} | ||
| onKeyPress={this.onKeyPress} | ||
| onChange={e => this.setState({ text: e.target.value })}/> | ||
| onChange={e => this.setState({ text: e.target.value },()=> console.log())}/> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty console log?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol fixed
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps some of your changes aren't committed yet? |
||
| </form> | ||
| {this.state.conversation.messages.slice().reverse().map((value, index) => { | ||
| return <p key={index}><b>{value.sender.name}: </b>{value.text}</p> | ||
| })} | ||
| </div> | ||
|
|
||
| <ChatFeed | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very clean integration with the React component! Finally make React work for us! |
||
| messages={[new Message({id: 1,message: this.state.conversation.lastMessage.text,senderName:this.state.user.name}), | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, so looks like this kind of changes the spec. I would imagine that breaks in conversation create a new chat bubble. Instead of only have a single chat bubble per user
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also we should clarify if a chat session only allows 2 users max
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if we only allow 2 users for now, for simplicity sake. and we can add group chat functionality in later version.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
do you mean each word would occupy one bubble, and as user type each word, more bubbles will pop out?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good on 2 users. Spun up an extra ticket to cover error handling (e.g. a 3rd user tries to join): #17 Let's see Issue #17 is outside the scope of this PR though and tackle that later. In terms of bubbles, my thought is: create new bubbles whenever the person talking changes. For example: Isaiah is talking (bubble 1 - blue) What do you think?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! Now I see that we needed to rename |
||
| new Message({id: 0,message: this.state.text,senderName:this.state.user.name})]} | ||
| showSenderName | ||
| /> | ||
|
|
||
|
|
||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,24 +11,19 @@ class Conversation { | |
| if(this.messages.length) { | ||
| return this.messages[this.messages.length - 1]; | ||
| } | ||
| return null; | ||
| return ''; | ||
| } | ||
| addMessage(message) { | ||
| message = Object.assign(new Message(), message); | ||
| message = Object.assign(new Msg(), message); | ||
| message.sender = Object.assign(new Sender(), message.sender); | ||
| let newSender = message.sender; | ||
| let lastMessage = this.lastMessage; | ||
| // return this; | ||
| if (lastMessage && newSender.equals(lastMessage.sender)) { | ||
| lastMessage.concat(message); | ||
| } else { | ||
| this.messages.push(message); | ||
| } | ||
| // let newSender = message.sender; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commented out code |
||
| // let lastMessage = this.lastMessage; | ||
| this.messages.push(message); | ||
| return this; | ||
| } | ||
| } | ||
|
|
||
| class Message { | ||
| class Msg { | ||
lx93 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| constructor(sender, text) { | ||
| this.sender = sender; | ||
| this.text = text; | ||
|
|
@@ -54,6 +49,6 @@ class Sender { | |
|
|
||
| export { | ||
| Conversation, | ||
| Message, | ||
| Msg, | ||
| Sender, | ||
| } | ||
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.
Having some functional issues when I test the app: