From 24a8a36c86e019d702a02a1c3cb8b14d1b6a813a Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 4 Nov 2026 11:58:38 +0300 Subject: [PATCH] feat(dashboard): digest previews, view modal, and digest deep-link handling --- public/dashboard.html | 39 +++++++++++++++++-- public/digest.html | 1 + public/js/dashboard.js | 85 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 114 insertions(+), 11 deletions(-) diff --git a/public/dashboard.html b/public/dashboard.html index fa4b353..c4eecde 100644 --- a/public/dashboard.html +++ b/public/dashboard.html @@ -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; } @@ -112,6 +126,23 @@ + + +
diff --git a/public/digest.html b/public/digest.html index caf711c..d839ee5 100644 --- a/public/digest.html +++ b/public/digest.html @@ -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; } diff --git a/public/js/dashboard.js b/public/js/dashboard.js index a4db14f..1b910ad 100644 --- a/public/js/dashboard.js +++ b/public/js/dashboard.js @@ -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 = '
Сообщений нет
'; return; } - el.innerHTML = rows.map(d => ` -
-
${esc(d.title)}
-
${esc(d.body)}
-
${esc(d.author_name || '—')} · ${fmtShortIso(d.created_at)}
-
- `).join(''); + el.innerHTML = rows.map(d => { + const preview = d.preview_path + ? 'превью' + : ''; + return '
' + + preview + + '
' + + '
' + esc(d.title) + '
' + + '
' + esc(d.body) + '
' + + '
' + esc(d.author_name || '—') + ' · ' + fmtShortIso(d.created_at) + '
' + + '
' + + '' + + 'Перейти →' + + '
' + + '
' + + '
'; + }).join(''); +} + +function digestViewImagesHtml(d) { + const images = Array.isArray(d.images) ? d.images : []; + if (!images.length) return ''; + return '
' + images.map(function(img) { + return '
' + esc(img.name || '') + '
'; + }).join('') + '
'; +} + +function renderDigestView(d) { + const pinned = !!d.is_pinned; + const preview = d.preview_path ? 'превью' : ''; + const images = digestViewImagesHtml(d); + const body = linkifyTextHtml(d.body || ''); + return '
' + + preview + + '
' + + '

' + esc(d.title) + '

' + + (pinned ? 'Закреплено' : '') + + '
' + + '
' + esc(d.author_name || '—') + ' · ' + fmtShortIso(d.created_at) + '
' + + '
' + body + '
' + + images + + '
'; +} + +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);