Skip to content

Commit

Permalink
added helpers.js + prettyDate function for converting millis to date …
Browse files Browse the repository at this point in the history
…string
  • Loading branch information
emir authored and kindaninja committed Mar 5, 2020
1 parent f6a4624 commit 79a6c0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
18 changes: 12 additions & 6 deletions app/routers/web_router.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const express = require('express');
const db = require('../persistence/sqlite');
const helpers = require('../utils/helpers');
const router = express.Router();

const PER_PAGE = 20;
Expand All @@ -23,7 +24,8 @@ router.get('/', async function(req, res) {
session_username: req.session.username,
session_user_id: req.session.user_id,
messages: messages,
myFeed: true
myFeed: true,
helpers: helpers
});
});

Expand All @@ -38,7 +40,8 @@ router.get('/public', async function(req, res) {
res.render('pages/timeline', {
session_username: req.session.username,
session_user_id: req.session.user_id,
messages: messages
messages: messages,
helpers: helpers
});
});

Expand Down Expand Up @@ -67,7 +70,8 @@ router.post('/add_message', async function(req, res) {
session_user_id: req.session.user_id,
session_username: req.session.username,
messages: messages,
myFeed: true
myFeed: true,
helpers: helpers
});
}
});
Expand Down Expand Up @@ -153,7 +157,8 @@ router.post('/login', async function(req, res) {
flashes: ['You were logged in'],
session_user_id: req.session.user_id,
session_username: req.session.username,
messages
messages,
helpers: helpers
});
}
}
Expand Down Expand Up @@ -202,7 +207,8 @@ router.get('/:username', async function(req, res) {
profile_username: profile_user.username,
profile_user_id: profile_user.user_id,
followed: !!followed,
messages: messages
messages: messages,
helpers: helpers
});
});

Expand Down Expand Up @@ -234,4 +240,4 @@ router.get('/:username/unfollow', async function(req, res) {



module.exports = router;
module.exports = router;
7 changes: 7 additions & 0 deletions app/utils/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function prettyDate(millis) {
return new Date(millis).toLocaleString();
}

module.exports = {
prettyDate: prettyDate
}
4 changes: 2 additions & 2 deletions app/views/pages/timeline.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<p>
<strong><a href="/<%= msg.username %>"><%= msg.username %></a></strong>
<%= msg.text %>
<small>&mdash; <%= msg.pub_date %></small>
<small>&mdash; <%= helpers.prettyDate(msg.pub_date) %></small>
</p>
</li>
<% }) %>
Expand All @@ -55,4 +55,4 @@
</ul>
<%- include('../partials/footer.ejs'); %>
<%- include('../partials/footer.ejs'); %>

0 comments on commit 79a6c0a

Please sign in to comment.