Skip to content

Commit

Permalink
now clearing out message after user sends it
Browse files Browse the repository at this point in the history
  • Loading branch information
bhubie committed Jul 19, 2017
1 parent b6cf245 commit 3fd87ca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h3>People</h3>

<div class="chat__footer">
<form id="message-form">
<input name="message" type="text" placeholder="Message"/>
<input name="message" type="text" placeholder="Message" autofocus autocomplete="off"/>
<button>Send</button>
</form>
<button id="send-location">Send Location to Users</button>
Expand Down
13 changes: 11 additions & 2 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,35 @@ socket.on('newLocationMessage', function(message){
jQuery('#message-form').on('submit', function(e){
e.preventDefault();

var messageTextBox = jQuery('[name=message]');

socket.emit('createMessage', {
from: 'User',
text: jQuery('[name=message]').val()
text: messageTextBox.val()
}, function(){

});

messageTextBox.val('');

});

var locationButton = jQuery('#send-location');
locationButtion.on('click', function(){
locationButton.on('click', function(){
if(!navigator.geolocation){
return alert('Geolocation not supported by your browser')
}

locationButton.attr('disabled', 'disabled').text('Sending Location...');

navigator.geolocation.getCurrentPosition(function(position){
locationButton.removeAttr('disabled').text('Send Location to Users');
socket.emit('createLocationMessage', {
latitude: position.coords.latitude,
longitude: position.coords.longitude
});
}, function(){
locationButton.removeAttr('disabled').text('Send Location to Users');
alert('Unable to get location')
});
});
Expand Down
2 changes: 1 addition & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ io.on('connection', (socket) => {
socket.on('createMessage', (message, callback) =>{
console.log('createMesse', message);
io.emit('newMessage', generateMessage(message.from, message.text));
callback('This is from the server');
callback();
});

socket.on('createLocationMessage', (coords) => {
Expand Down

0 comments on commit 3fd87ca

Please sign in to comment.