feat(journal): скелетон загрузки фото в списке записей
This commit is contained in:
+47
-2
@@ -49,6 +49,10 @@ function mainPhotoPath(e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function journalImgHTML(mp) {
|
||||
return `<div class="img-media"><img class="img-load" src="${thumbSrc(mp)}" data-img="${API}${mp}" loading="lazy" decoding="async" alt=""><div class="img-skeleton"><span class="img-spin"></span><span>Загрузка…</span></div></div>`;
|
||||
}
|
||||
|
||||
const REPORT_CARD_FIELDS = [
|
||||
{ key: 'photo', label: 'Фото' },
|
||||
{ key: 'lastname', label: 'Фамилия' },
|
||||
@@ -251,7 +255,7 @@ function gridEntryHTML(e) {
|
||||
const mp = mainPhotoPath(e);
|
||||
return `
|
||||
<div class="card${highlightNewIds.has(e.id) ? ' entry-appear' : ' entry-enter'}">
|
||||
${mp ? `<img src="${thumbSrc(mp)}" data-img="${API}${mp}" loading="lazy" decoding="async" alt="">` : ''}
|
||||
${mp ? journalImgHTML(mp) : ''}
|
||||
<div class="info">
|
||||
<div class="name">${esc(e.student_name)}</div>
|
||||
<div class="group">${esc(e.group_name)}${e.module_name ? ' · ' + esc(e.module_name) : ''}</div>
|
||||
@@ -272,7 +276,7 @@ function cardEntryHTML(e) {
|
||||
return `
|
||||
<div class="journal-card${highlightNewIds.has(e.id) ? ' entry-appear' : ' entry-enter'}">
|
||||
${mp
|
||||
? `<img src="${thumbSrc(mp)}" data-img="${API}${mp}" loading="lazy" decoding="async" alt="">`
|
||||
? journalImgHTML(mp)
|
||||
: `<div class="no-photo"><svg viewBox="0 0 240 160" preserveAspectRatio="xMidYMid meet" aria-hidden="true"><circle cx="105" cy="48" r="15"/><path d="M74 140 C74 106 88 92 105 92 C122 92 136 106 136 140 Z"/><circle cx="145" cy="58" r="18"/><path d="M108 144 C108 104 124 88 145 88 C166 88 182 104 182 144 Z"/></svg></div>`}
|
||||
${e.group_name ? `<span class="group-badge" title="${esc(e.group_name)}">${esc(e.group_name)}</span>` : ''}
|
||||
${e.module_name ? `<span class="group-badge" style="left:auto;right:8px;background:rgba(37,99,235,.8)" title="Модуль: ${esc(e.module_name)}">${esc(e.module_name)}</span>` : ''}
|
||||
@@ -320,6 +324,45 @@ function renderGrid() {
|
||||
el.style.animationDelay = `${Math.min(i * 45, 500)}ms`;
|
||||
});
|
||||
renderIcons();
|
||||
settleJournalThumbs(grid);
|
||||
}
|
||||
|
||||
function settleJournalThumbs(root) {
|
||||
if (!root) return;
|
||||
root.querySelectorAll('.img-media img.img-load, .img-media img.img-error').forEach((img) => {
|
||||
if (img.complete && img.naturalWidth > 0) {
|
||||
img.classList.remove('img-load', 'img-error');
|
||||
img.classList.add('img-loaded');
|
||||
} else if (img.complete && img.naturalWidth === 0) {
|
||||
img.classList.remove('img-load');
|
||||
img.classList.add('img-error');
|
||||
const sk = img.parentElement && img.parentElement.querySelector('.img-skeleton');
|
||||
if (sk) sk.innerHTML = '<span>Нет фото</span>';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function bindJournalThumbLoading() {
|
||||
const grid = document.getElementById('grid');
|
||||
if (!grid) return;
|
||||
const settle = (img) => {
|
||||
if (!img || !img.classList) return;
|
||||
img.classList.remove('img-load', 'img-error');
|
||||
img.classList.add('img-loaded');
|
||||
};
|
||||
const fail = (img) => {
|
||||
if (!img || !img.classList) return;
|
||||
img.classList.remove('img-load');
|
||||
img.classList.add('img-error');
|
||||
const sk = img.parentElement && img.parentElement.querySelector('.img-skeleton');
|
||||
if (sk) sk.innerHTML = '<span>Нет фото</span>';
|
||||
};
|
||||
grid.addEventListener('load', (e) => {
|
||||
if (e.target.tagName === 'IMG') settle(e.target);
|
||||
}, true);
|
||||
grid.addEventListener('error', (e) => {
|
||||
if (e.target.tagName === 'IMG') fail(e.target);
|
||||
}, true);
|
||||
}
|
||||
|
||||
function refreshEntryCardDom(e) {
|
||||
@@ -333,6 +376,7 @@ function refreshEntryCardDom(e) {
|
||||
fresh.style.animationDelay = '';
|
||||
card.replaceWith(fresh);
|
||||
renderIcons();
|
||||
settleJournalThumbs(fresh);
|
||||
}
|
||||
|
||||
async function refreshEntryCard(id) {
|
||||
@@ -1953,6 +1997,7 @@ document.getElementById('linkCopyBtn').addEventListener('click', copyLink);
|
||||
(async () => {
|
||||
if (await checkAuth()) {
|
||||
buildSidebar(document.body.dataset.page);
|
||||
bindJournalThumbLoading();
|
||||
document.querySelectorAll('#viewToggle button').forEach(b => {
|
||||
b.classList.toggle('active', b.dataset.view === view);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user