Skip to content

Commit c85e351

Browse files
committed
removed livestamp.js & added shared timestamp formatting
1 parent 9b0487a commit c85e351

4 files changed

Lines changed: 38 additions & 21 deletions

File tree

app/assets/javascripts/livestamp.min.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

app/assets/javascripts/notifications.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
$(() => {
22
/**
3-
* @param {QPixelNotification} notification
3+
* @param {QPixelNotification} notification
44
*/
55
const makeNotification = (notification) => {
66
const template = `<div class="js-notification widget h-m-0 h-m-b-2 ${notification.is_read ? 'read' : 'is-teal'}">
77
<div class="widget--body h-p-2">
88
<div class="h-c-tertiary-600 h-fs-caption">
99
${notification.community_name} &middot;
1010
<span class="js-notif-state">${notification.is_read ? 'read' : `<strong>unread</strong>`}</span> &middot;
11-
<span data-livestamp="${notification.created_at}">${notification.created_at}</span>
11+
<span title="${notification.created_at}">${QPixel.DOM.formatTimestamp(notification.created_at)}</span>
1212
</div>
1313
<p><a href="${notification.link}" data-id="${notification.id}"
1414
class="h-fw-bold is-not-underlined ${notification.is_read ? 'read' : ''} notification-link">${notification.content}</a></p>
@@ -22,7 +22,7 @@ $(() => {
2222
};
2323

2424
/**
25-
* @param {number} change
25+
* @param {number} change
2626
*/
2727
const changeInboxCount = (change) => {
2828
const counter = $('.inbox-count');
@@ -51,20 +51,20 @@ $(() => {
5151
$('.inbox-toggle').on('click', async (ev) => {
5252
ev.preventDefault();
5353
const $inbox = $('.inbox');
54-
if($inbox.hasClass("is-active")) {
54+
if ($inbox.hasClass('is-active')) {
5555
const data = await QPixel.getNotifications();
5656

57-
const $inboxContainer = $inbox.find(".inbox--container");
57+
const $inboxContainer = $inbox.find('.inbox--container');
5858
$inboxContainer.html('');
59-
59+
6060
const unread = data.filter((n) => !n.is_read);
6161
const read = data.filter((n) => n.is_read);
62-
62+
6363
unread.forEach((notification) => {
6464
const item = $(makeNotification(notification));
6565
$inboxContainer.append(item);
6666
});
67-
67+
6868
$inboxContainer.append(`<div role="separator" class="header-slide--separator"></div>`);
6969
read.forEach((notification) => {
7070
const item = $(makeNotification(notification));
@@ -76,9 +76,13 @@ $(() => {
7676
$('.js-read-all-notifs').on('click', async (ev) => {
7777
ev.preventDefault();
7878

79-
await QPixel.fetchJSON('/notifications/read_all', {}, {
80-
headers: { 'Accept': 'application/json' }
81-
});
79+
await QPixel.fetchJSON(
80+
'/notifications/read_all',
81+
{},
82+
{
83+
headers: { Accept: 'application/json' },
84+
},
85+
);
8286

8387
$('.inbox-count').remove();
8488

@@ -91,9 +95,13 @@ $(() => {
9195
const $tgt = $(evt.target);
9296
const id = $tgt.data('id');
9397

94-
const resp = await QPixel.fetchJSON(`/notifications/${id}/read`, {}, {
95-
headers: { 'Accept': 'application/json' }
96-
});
98+
const resp = await QPixel.fetchJSON(
99+
`/notifications/${id}/read`,
100+
{},
101+
{
102+
headers: { Accept: 'application/json' },
103+
},
104+
);
97105

98106
const data = await resp.json();
99107
$tgt.parents('.js-notification')[0].outerHTML = makeNotification(data.notification);
@@ -106,9 +114,13 @@ $(() => {
106114
const $tgt = $(ev.target).is('a') ? $(ev.target) : $(ev.target).parents('a');
107115
const id = $tgt.attr('data-notif-id');
108116

109-
const resp = await QPixel.fetchJSON(`/notifications/${id}/read`, {}, {
110-
headers: { 'Accept': 'application/json' }
111-
});
117+
const resp = await QPixel.fetchJSON(
118+
`/notifications/${id}/read`,
119+
{},
120+
{
121+
headers: { Accept: 'application/json' },
122+
},
123+
);
112124

113125
const data = await resp.json();
114126
if (data.status !== 'success') {

app/assets/javascripts/qpixel_dom.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ window.QPixel ||= {};
5656
}, duration);
5757
},
5858

59+
formatTimestamp: (timestamp) => {
60+
return moment(timestamp).format('YYYY-MM-DD [at] hh:mm:ss UTC');
61+
},
62+
5963
getModifierState: (e) => {
6064
return !!e.altKey || !!e.ctrlKey || !!e.metaKey || !!e.shiftKey;
6165
},

global.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ interface QPixelDOM {
5858
* @param duration A duration for the effect in milliseconds.
5959
*/
6060
fadeOut?: (element: HTMLElement, duration: number) => void;
61+
/**
62+
* Formats a given {@link timestamp} with the standard format
63+
* @param timestamp timestamp to format
64+
*/
65+
formatTimestamp?: (timestamp: string | number | Date) => string;
6166
/**
6267
* Checks common modifier states on a given keyboard event
6368
* @param event

0 commit comments

Comments
 (0)