Cleanup updateDate code

This commit is contained in:
Rob Garrison 2018-11-30 21:56:26 -06:00
parent 52f012daf5
commit 9368c27990
2 changed files with 18 additions and 30 deletions

View File

@ -66,9 +66,6 @@ function initGlobalEvents() {
btn.onclick = btn.onclick || (() => openURL({url: URLS.configureCommands})); btn.onclick = btn.onclick || (() => openURL({url: URLS.configureCommands}));
$$('#header a[href^="http"]').forEach(a => (a.onclick = handleEvent.external)); $$('#header a[href^="http"]').forEach(a => (a.onclick = handleEvent.external));
// show date installed & last update on hover
installed.addEventListener('mouseover', handleEvent.lazyAddEntryTitle);
installed.addEventListener('mouseout', handleEvent.lazyAddEntryTitle);
document.addEventListener('visibilitychange', onVisibilityChange); document.addEventListener('visibilitychange', onVisibilityChange);
@ -272,28 +269,8 @@ Object.assign(handleEvent, {
config(event, {styleMeta}) { config(event, {styleMeta}) {
event.preventDefault(); event.preventDefault();
configDialog(styleMeta); configDialog(styleMeta);
}, }
lazyAddEntryTitle({type, target}) {
const cell = target.closest('h2.style-name');
if (cell) {
const link = $('.style-name-link', cell);
if (type === 'mouseover' && !link.title) {
debounce(handleEvent.addEntryTitle, 50, link);
} else {
debounce.unregister(handleEvent.addEntryTitle);
}
}
},
addEntryTitle(link) {
const entry = link.closest('.entry');
link.title = [
{prop: 'installDate', name: 'dateInstalled'},
{prop: 'updateDate', name: 'dateUpdated'},
].map(({prop, name}) =>
t(name) + ': ' + (formatDate(entry.styleMeta[prop]) || '—')).join('\n');
}
}); });
function handleUpdate(style, {reason, method} = {}) { function handleUpdate(style, {reason, method} = {}) {

View File

@ -1,6 +1,7 @@
/* /*
global prefs $ $$ $create template tWordBreak global prefs t $ $$ $create template tWordBreak
installed sorter filterAndAppend installed sorter filterAndAppend handleEvent
animateElement scrollElementIntoView formatDate
*/ */
'use strict'; 'use strict';
@ -158,10 +159,13 @@ const UI = {
$('.entry-version', entry).textContent = style.usercssData && style.usercssData.version || ''; $('.entry-version', entry).textContent = style.usercssData && style.usercssData.version || '';
let lastUpdate = style.updateDate ? new Date(style.updateDate) : ''; const lastUpdate = $('.entry-last-update', entry);
lastUpdate = lastUpdate instanceof Date && isFinite(lastUpdate) ? lastUpdate.toISOString() : ''; lastUpdate.textContent = UI.getDateString(style.updateDate);
$('.entry-last-update', entry).textContent = lastUpdate.split('T')[0].replace(/-/g, '.'); // Show install & last update in title
$('.entry-last-update', entry).title = lastUpdate; lastUpdate.title = [
{prop: 'installDate', name: 'dateInstalled'},
{prop: 'updateDate', name: 'dateUpdated'},
].map(({prop, name}) => t(name) + ': ' + (formatDate(entry.styleMeta[prop]) || '—')).join('\n');
UI.createStyleTargetsElement({entry, style}); UI.createStyleTargetsElement({entry, style});
UI.addLabels(entry); UI.addLabels(entry);
@ -169,6 +173,13 @@ const UI = {
return entry; return entry;
}, },
getDateString: date => {
const newDate = new Date(date);
return newDate instanceof Date && isFinite(newDate)
? newDate.toISOString().split('T')[0].replace(/-/g, '.')
: '';
},
createStyleTargetsElement: ({entry, style}) => { createStyleTargetsElement: ({entry, style}) => {
const parts = UI._parts; const parts = UI._parts;