Move pages.meet painting to a .paint() method

This commit is contained in:
Niko 2022-02-16 21:22:51 +01:00
parent 4c562ebaff
commit 4b494dcc7a
1 changed files with 49 additions and 42 deletions

View File

@ -1,55 +1,62 @@
app.pages.meet = { app.pages.meet = {
data: [],
load: function(args) { load: function(args) {
document.querySelector('#page-meet').removeAttribute('style');
const dom = document.querySelector('#page-meet #content'); const dom = document.querySelector('#page-meet #content');
dom.innerHTML = ''; dom.innerHTML = '';
document.querySelector('#page-meet').removeAttribute('style');
http.get('/api/v1/feed/meet', {}, function(json) { http.get('/api/v1/feed/meet', {}, function(json) {
if (json === undefined) return; if (json === undefined) return;
app.pages.meet.data = json;
app.template.loadMany(['meet.item','meet.actions'], function(_) { app.template.loadMany(['meet.item','meet.actions'], function(_) {
var _; app.pages.meet.paint(json);
_ = function () {
for (var i = 0; i < json.length; i++) {
var tpl = app.template.fill(json[i], app.template.get('meet.item'),
function (k,v) {
if (k === 'text') return html2text(v);
if (k === 'account.name') return capitalize(v);
if (k === 'date') return dayjs(v).fromNow(true);
});
var item = json[i];
if (item.props === undefined)
item.props = { pcolors: {} }
if (item.account.props.pcolors === undefined)
item.account.props.pcolors = {};
var postFgColor = item.account.props.pcolors.fg
|| app.vars.defaults.meet.item_pcolors.fg;
var postBgColor = item.account.props.pcolors.bg
|| app.vars.defaults.meet.item_pcolors.bg;
if (item.props.pcolors.fg !== undefined)
postFgColor = item.props.pcolors.fg;
if (item.props.pcolors.bg !== undefined)
postBgColor = item.props.pcolors.bg;
tpl = tpl.replaceAll('{actionsHeight}', '6em');
tpl = tpl.replaceAll('{postFgColor}', htmlescape(postFgColor));
tpl = tpl.replaceAll('{postBgColor}', htmlescape(postBgColor));
dom.innerHTML += tpl;
}
}; _();
_ = function () {
const dom = document.querySelector('#page-meet #actions');
dom.innerHTML = '';
dom.style.height = '6em';
var tpl = app.template.fill({}, app.template.get('meet.actions'));
dom.innerHTML += tpl;
}; _();
var index = app.storage.get('status_meet_index');
if (index === undefined)
index = 0;
app.pages.meet.carousel.set(parseInt(index));
}); });
}); });
}, },
paint: function(json) {
json = json || app.pages.meet.data;
let _;
_ = function () {
const dom = document.querySelector('#page-meet #content');
dom.innerHTML = '';
for (var i = 0; i < json.length; i++) {
var tpl = app.template.fill(json[i], app.template.get('meet.item'),
function (k,v) {
if (k === 'text') return html2text(v);
if (k === 'account.name') return capitalize(v);
if (k === 'date') return dayjs(v).fromNow(true);
});
var item = json[i];
if (item.props === undefined)
item.props = { pcolors: {} }
if (item.account.props.pcolors === undefined)
item.account.props.pcolors = {};
var postFgColor = item.account.props.pcolors.fg
|| app.vars.defaults.meet.item_pcolors.fg;
var postBgColor = item.account.props.pcolors.bg
|| app.vars.defaults.meet.item_pcolors.bg;
if (item.props.pcolors.fg !== undefined)
postFgColor = item.props.pcolors.fg;
if (item.props.pcolors.bg !== undefined)
postBgColor = item.props.pcolors.bg;
tpl = tpl.replaceAll('{actionsHeight}', '6em');
tpl = tpl.replaceAll('{postFgColor}', htmlescape(postFgColor));
tpl = tpl.replaceAll('{postBgColor}', htmlescape(postBgColor));
dom.innerHTML += tpl;
}
}; _();
_ = function () {
const dom = document.querySelector('#page-meet #actions');
dom.innerHTML = '';
dom.style.height = '6em';
var tpl = app.template.fill({}, app.template.get('meet.actions'));
dom.innerHTML += tpl;
}; _();
var index = app.storage.get('status_meet_index') || 0;
app.pages.meet.carousel.set(parseInt(index));
},
exit: function() { exit: function() {
window.location.href = '#'; window.location.href = '#';
app.overlay.hideAll(); app.overlay.hideAll();