Skip to content

Commit

Permalink
adding moment
Browse files Browse the repository at this point in the history
  • Loading branch information
paras151 committed Aug 5, 2019
1 parent 00b9a3d commit 1f917b6
Show file tree
Hide file tree
Showing 8 changed files with 4,649 additions and 13 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"moment": "^2.24.0",
"socket.io": "^2.2.0"
},
"devDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions playground/time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var moment = require('moment');

var date = moment();

console.log(date.format('MMM Do, YYYY'));

console.log(date.format('LT a'))
1 change: 1 addition & 0 deletions public/css/styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 20 additions & 8 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,35 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel = "stylesheet" href="css/styles.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<p>Welcome to body</p>
<body class="chat">

<ol id="messages"></ol>
<div class="chat__sidebar">
<h3>People</h3>
<div id="users"></div>
</div>

<form id="message-form">
<input name="message" type="text" placeholder="Mesage"/>
<button>Send</button>
</form>
<div class="chat__main">
<ol id="messages" class="chat__messages"></ol>

<button id="send-location">Send location</button>
<div class="chat__footer">
<form id="message-form">
<input id="msg" name="message" type="text" placeholder="Mesage"/>
<button>Send</button>
</form>

<button id="send-location">Send location</button>
</div>

</div>

<script src = "/socket.io/socket.io.js"></script>
<script src = "js/libs/jquery-3.4.1.min.js"></script>
<script src = "js/libs/moment.js"></script>
<script src = "js/index.js"></script>
</body>
</html>
13 changes: 10 additions & 3 deletions public/js/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


var socket = io();

socket.on('connect',function(){
Expand All @@ -12,16 +14,18 @@ socket.on('disconnect',function(){

socket.on('newMessage',function(message){
// console.log("New Message",message);

var formattedTime = moment(message.createdAt).format('LT');
var li = jQuery('<li></li>');
li.text(`${message.from}: ${message.text}`)
li.text(`${message.from} ${formattedTime}: ${message.text}`)
jQuery('#messages').append(li);
})

socket.on('newLocationMessage',function(message){
var li = jQuery('<li></li>');
var a = jQuery('<a target="_blank">My current location</a>')
li.text(`${message.from}: `);
var formattedTime = moment(message.createdAt).format('LT');

li.text(`${message.from} ${formattedTime}: `);
a.attr('href',message.url);
li.append(a);
jQuery('#messages').append(li);
Expand All @@ -44,8 +48,11 @@ jQuery('#message-form').on('submit',function(e){
from:'User',
text:jQuery('[name=message]').val()
},function(){


})
// jQuery('[name=message]').val('');

})

var locationButton = jQuery('#send-location');
Expand Down
Loading

0 comments on commit 1f917b6

Please sign in to comment.