feat(dashboard): digest previews, view modal, and digest deep-link handling

This commit is contained in:
dev
2026-11-04 11:58:38 +03:00
parent 9dd8ba20c0
commit 24a8a36c86
3 changed files with 114 additions and 11 deletions
+35 -4
View File
@@ -21,10 +21,24 @@
.post-task-hint { margin-top:6px; padding:6px 10px; border-radius:6px; background:rgba(239,68,68,.08); border:1px solid rgba(239,68,68,.3); color:#b91c1c; font-size:12px; line-height:1.4; }
.post-task-actions { display:flex; gap:6px; flex-wrap:wrap; margin-top:8px; }
.post-task-actions .btn-xs { padding:4px 10px; font-size:12px; }
.digest-dash-item { border:1px solid var(--border); border-radius:10px; padding:10px 12px; margin-bottom:8px; background:var(--card); }
.digest-dash-title { font-weight:600; font-size:.92rem; margin:0 0 4px 0; word-break:break-word; }
.digest-dash-body { font-size:.86rem; line-height:1.5; color:var(--text); margin-bottom:6px; word-break:break-word; }
.digest-dash-foot { font-size:.78rem; color:var(--muted); display:flex; gap:8px; align-items:center; }
.digest-dash-item { border:1px solid var(--border); border-radius:10px; padding:10px 12px; margin-bottom:8px; background:var(--card); display:flex; gap:10px; align-items:flex-start; }
.digest-dash-preview { width:70px; height:55px; object-fit:cover; border:1px solid var(--border); border-radius:6px; flex-shrink:0; margin-top:2px; }
.digest-dash-main { flex:1; min-width:0; display:flex; flex-direction:column; gap:6px; }
.digest-dash-title { font-weight:600; font-size:.92rem; margin:0; word-break:break-word; }
.digest-dash-text { font-size:.86rem; line-height:1.5; color:var(--text); margin:0; word-break:break-word; display:-webkit-box; -webkit-line-clamp:3; -webkit-box-orient:vertical; overflow:hidden; }
.digest-dash-foot { font-size:.78rem; color:var(--muted); margin-top:auto; }
.digest-dash-actions { display:flex; gap:8px; margin-top:6px; flex-shrink:0; }
.digest-view { display:flex; flex-direction:column; gap:12px; }
.digest-view-preview { width:100%; max-height:320px; object-fit:cover; border:1px solid var(--border); border-radius:10px; }
.digest-view-head { display:flex; justify-content:space-between; align-items:center; gap:10px; flex-wrap:wrap; }
.digest-view-title { margin:0; font-size:1.25rem; word-break:break-word; }
.digest-view-meta { font-size:.82rem; color:var(--muted); }
.digest-view-body { font-size:1rem; line-height:1.7; color:var(--text); }
.digest-view-body a { color:var(--accent); text-decoration:underline; }
.digest-modal-body { max-height: 60vh; overflow-y: auto; padding: 12px 0 8px 0; }
.digest-view-images { display:flex; gap:10px; flex-wrap:wrap; margin-top:6px; }
.digest-view-image { position:relative; border:1px solid var(--border); border-radius:8px; overflow:hidden; width:150px; height:110px; flex-shrink:0; cursor:pointer; }
.digest-view-image img { width:100%; height:100%; object-fit:cover; display:block; }
</style>
</head>
<body data-page="dashboard">
@@ -112,6 +126,23 @@
<div class="modal-overlay" id="imgModal">
<img id="imgModalSrc" alt="">
</div>
<div class="modal-overlay" id="digestViewModal">
<div class="edit-modal" style="width:1000px;max-width:none">
<div class="bookmark-modal-head">
<h3 id="digestViewTitle">Дайджест</h3>
<button type="button" class="icon-btn" id="digestViewClose"><i data-lucide="x"></i></button>
</div>
<div class="digest-modal-body">
<div id="digestViewContent"></div>
</div>
<div class="card-foot">
<button type="button" class="btn-primary ghost" id="digestViewCloseBtn">Закрыть</button>
<a id="digestViewGo" class="btn-primary" href="#" style="margin-left:auto">Открыть в дайджесте →</a>
</div>
</div>
</div>
<div class="toast" id="toast"></div>
<script src="vendor/lucide.min.js"></script>
<script src="js/datetime.js"></script>
+1
View File
@@ -35,6 +35,7 @@
.digest-shot-zoom { position: absolute; bottom: 4px; right: 4px; background: rgba(0,0,0,.55); color: #fff; border-radius: 4px; padding: 2px 5px; font-size: .65rem; opacity: 0; transition: opacity .15s; }
.digest-shot:hover .digest-shot-zoom { opacity: 1; }
.digest-hidden { opacity: 0.72; }
.digest-highlight { outline: 2px solid #f59e0b; outline-offset: 2px; border-radius: 8px; }
#digestModal .edit-modal { width: 1000px; max-width: none; }
#digestModal .bookmark-modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.digest-modal-body { max-height: 62vh; overflow-y: auto; padding: 12px 0 8px 0; }
+78 -7
View File
@@ -222,17 +222,70 @@ function renderLessons(rows) {
}).join('');
}
let dashDigestItems = [];
function renderDigest(rows) {
const el = document.getElementById('dashDigest');
if (!el) return;
dashDigestItems = rows;
if (!rows.length) { el.innerHTML = '<div class="dash-empty">Сообщений нет</div>'; return; }
el.innerHTML = rows.map(d => `
<div class="digest-dash-item">
<div class="digest-dash-title">${esc(d.title)}</div>
<div class="digest-dash-body">${esc(d.body)}</div>
<div class="digest-dash-foot">${esc(d.author_name || '—')} · ${fmtShortIso(d.created_at)}</div>
</div>
`).join('');
el.innerHTML = rows.map(d => {
const preview = d.preview_path
? '<img src="' + thumbSrc(d.preview_path) + '" class="digest-dash-preview" alt="превью">'
: '';
return '<div class="digest-dash-item" data-id="' + d.id + '">' +
preview +
'<div class="digest-dash-main">' +
'<div class="digest-dash-title">' + esc(d.title) + '</div>' +
'<div class="digest-dash-text">' + esc(d.body) + '</div>' +
'<div class="digest-dash-foot">' + esc(d.author_name || '—') + ' · ' + fmtShortIso(d.created_at) + '</div>' +
'<div class="digest-dash-actions">' +
'<button type="button" class="btn-xs" data-action="open-digest" data-id="' + d.id + '">Открыть</button>' +
'<a href="digest.html?id=' + d.id + '" class="btn-link btn-xs">Перейти →</a>' +
'</div>' +
'</div>' +
'</div>';
}).join('');
}
function digestViewImagesHtml(d) {
const images = Array.isArray(d.images) ? d.images : [];
if (!images.length) return '';
return '<div class="digest-view-images">' + images.map(function(img) {
return '<div class="digest-view-image"><img src="' + thumbSrc(img.path) + '" data-img="' + API + img.path + '" alt="' + esc(img.name || '') + '" loading="lazy" decoding="async"></div>';
}).join('') + '</div>';
}
function renderDigestView(d) {
const pinned = !!d.is_pinned;
const preview = d.preview_path ? '<img src="' + thumbSrc(d.preview_path) + '" data-img="' + API + d.preview_path + '" class="digest-view-preview" alt="превью">' : '';
const images = digestViewImagesHtml(d);
const body = linkifyTextHtml(d.body || '');
return '<div class="digest-view">' +
preview +
'<div class="digest-view-head">' +
'<h2 class="digest-view-title">' + esc(d.title) + '</h2>' +
(pinned ? '<span class="digest-badge">Закреплено</span>' : '') +
'</div>' +
'<div class="digest-view-meta">' + esc(d.author_name || '—') + ' · ' + fmtShortIso(d.created_at) + '</div>' +
'<div class="digest-view-body" style="white-space:pre-wrap;word-break:break-word">' + body + '</div>' +
images +
'</div>';
}
function openDigestView(id) {
const d = dashDigestItems.find(function(x) { return x.id === id; });
if (!d) return;
document.getElementById('digestViewTitle').textContent = esc(d.title);
document.getElementById('digestViewContent').innerHTML = renderDigestView(d);
document.getElementById('digestViewGo').href = 'digest.html?id=' + d.id;
document.getElementById('digestViewModal').classList.add('open');
renderIcons();
}
function closeDigestView() {
document.getElementById('digestViewModal').classList.remove('open');
document.getElementById('digestViewContent').innerHTML = '';
}
async function loadDigest() {
@@ -314,6 +367,24 @@ if (closeAllTasksBtn) closeAllTasksBtn.addEventListener('click', () => {
loadDashboard();
});
document.getElementById('digestViewClose').addEventListener('click', closeDigestView);
document.getElementById('digestViewCloseBtn').addEventListener('click', closeDigestView);
document.getElementById('digestViewModal').addEventListener('click', function(e) {
if (e.target === e.currentTarget) closeDigestView();
});
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && document.getElementById('digestViewModal').classList.contains('open')) closeDigestView();
});
document.addEventListener('click', function(e) {
const btn = e.target.closest('[data-action="open-digest"]');
if (btn) {
e.preventDefault();
openDigestView(parseInt(btn.dataset.id, 10));
return;
}
});
(async () => {
if (await checkAuth()) {
buildSidebar(document.body.dataset.page);