Fix digest page and logic
This commit is contained in:
+44
-22
@@ -6,16 +6,30 @@
|
||||
<title>Дайджест — Админ-панель</title>
|
||||
<link rel="stylesheet" href="admin.css">
|
||||
<style>
|
||||
.digest-page { max-width: 1080px; width: 100%; margin: 0 auto; }
|
||||
.digest-toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
|
||||
.digest-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 20px; align-items: start; }
|
||||
.digest-side { position: sticky; top: 20px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; max-height: calc(100dvh - 40px); }
|
||||
.digest-side-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
|
||||
.digest-side-title { font-size: .85rem; font-weight: 700; white-space: nowrap; }
|
||||
.digest-side-search { padding: 10px 12px; border-bottom: 1px solid var(--border); }
|
||||
.digest-side-search .digest-search { min-width: 0; max-width: none; }
|
||||
.digest-nav { overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
|
||||
.digest-nav-item { display: flex; flex-direction: column; gap: 3px; width: 100%; padding: 10px 14px; text-align: left; background: transparent; border: none; border-bottom: 1px solid var(--border); font-family: inherit; cursor: pointer; transition: background .15s; }
|
||||
.digest-nav-item:last-child { border-bottom: none; }
|
||||
.digest-nav-item:hover { background: var(--bg); }
|
||||
.digest-nav-item.active { background: rgba(37,99,235,.07); box-shadow: inset 3px 0 0 var(--accent); }
|
||||
.digest-nav-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: .85rem; font-weight: 600; line-height: 1.35; color: var(--text); overflow-wrap: anywhere; }
|
||||
.digest-nav-title svg { width: 12px; height: 12px; margin-right: 4px; vertical-align: -1px; color: #b45309; }
|
||||
.digest-nav-date { font-size: .72rem; color: var(--muted); white-space: nowrap; }
|
||||
.digest-nav-empty { padding: 22px 14px; color: var(--muted); font-size: .85rem; text-align: center; }
|
||||
|
||||
.digest-search { position: relative; flex: 1; min-width: 240px; max-width: 460px; display: flex; align-items: center; }
|
||||
.digest-search > svg { position: absolute; left: 14px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
|
||||
.digest-search input { width: 100%; background: var(--card); border: 1px solid var(--border); color: var(--text); border-radius: 11px; padding: 11px 14px 11px 40px; font-size: .9rem; font-family: inherit; outline: none; transition: border-color .15s, box-shadow .15s; }
|
||||
.digest-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
|
||||
.digest-count { font-size: .82rem; font-weight: 500; color: var(--muted); margin-left: auto; white-space: nowrap; }
|
||||
.digest-list { display: flex; flex-direction: column; gap: 20px; margin-top: 18px; }
|
||||
.digest-count { font-size: .75rem; font-weight: 500; color: var(--muted); margin-left: auto; white-space: nowrap; }
|
||||
.digest-list { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
|
||||
|
||||
.digest-card { position: relative; background: var(--card); border: 1px solid var(--border); border-radius: 16px; display: flex; flex-direction: column; min-width: 0; overflow: hidden; transition: box-shadow .18s, border-color .18s; }
|
||||
.digest-card { position: relative; background: var(--card); border: 1px solid var(--border); border-radius: 16px; display: flex; flex-direction: column; min-width: 0; overflow: hidden; scroll-margin-top: 20px; transition: box-shadow .18s, border-color .18s; }
|
||||
.digest-card:hover { box-shadow: 0 6px 24px rgba(0,0,0,.06); }
|
||||
.digest-card.pinned { border-left: 3px solid #f59e0b; background: linear-gradient(180deg, rgba(245,158,11,.055), var(--card) 180px); }
|
||||
.digest-card.digest-hidden { opacity: .62; }
|
||||
@@ -48,11 +62,11 @@
|
||||
.digest-body-toggle svg { width: 14px; height: 14px; transition: transform .18s; }
|
||||
.digest-body-toggle.open svg { transform: rotate(180deg); }
|
||||
|
||||
.digest-gallery { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
|
||||
.digest-shot { position: relative; display: block; width: 100%; aspect-ratio: 4/3; padding: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--bg); cursor: zoom-in; }
|
||||
.digest-gallery { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.digest-shot { position: relative; display: block; width: 68px; aspect-ratio: 4/3; flex: 0 0 auto; padding: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--bg); cursor: zoom-in; }
|
||||
.digest-shot img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s ease; }
|
||||
.digest-shot:hover img { transform: scale(1.05); }
|
||||
.digest-more { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(17,24,39,.55); color: #fff; font-size: 1.05rem; font-weight: 700; pointer-events: none; }
|
||||
.digest-more { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(17,24,39,.55); color: #fff; font-size: .72rem; font-weight: 700; pointer-events: none; }
|
||||
|
||||
.digest-foot { margin-top: 20px; padding: 14px 28px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap; }
|
||||
.digest-foot-note { display: inline-flex; align-items: center; gap: 5px; font-size: .76rem; color: var(--muted); }
|
||||
@@ -100,15 +114,17 @@
|
||||
.digest-check input { width: auto; }
|
||||
#digestModal .card-foot { flex: 0 0 auto; margin-top: 10px; justify-content: flex-end; }
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.digest-layout { grid-template-columns: 1fr; gap: 16px; }
|
||||
.digest-side { position: static; max-height: 260px; }
|
||||
}
|
||||
@media (max-width: 720px) {
|
||||
.digest-card-top { padding: 20px 18px 0; }
|
||||
.digest-main { flex-direction: column; gap: 16px; padding: 16px 18px 0; }
|
||||
.digest-cover { flex: none; width: 100%; max-width: none; }
|
||||
.digest-foot { padding: 12px 18px; }
|
||||
.digest-title { font-size: 1.18rem; }
|
||||
.digest-gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
.digest-modal-grid { grid-template-columns: 1fr; }
|
||||
.digest-count { margin-left: 0; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
@@ -116,19 +132,25 @@
|
||||
<div class="layout">
|
||||
<div class="sidebar" id="sidebar"></div>
|
||||
<div class="main">
|
||||
<div class="digest-page">
|
||||
<div class="page-head">
|
||||
<h2>Дайджест</h2>
|
||||
<p class="page-sub">Важные сообщения для команды</p>
|
||||
<button type="button" class="btn-primary digest-new-btn" id="digestNewBtn"><i data-lucide="plus"></i> Новое сообщение</button>
|
||||
</div>
|
||||
<div class="digest-toolbar">
|
||||
<div class="digest-search">
|
||||
<i data-lucide="search"></i>
|
||||
<input type="search" id="digestSearch" placeholder="Поиск по заголовку, тексту или автору" autocomplete="off">
|
||||
<div class="page-head">
|
||||
<h2>Дайджест</h2>
|
||||
<p class="page-sub">Важные сообщения для команды</p>
|
||||
<button type="button" class="btn-primary digest-new-btn" id="digestNewBtn"><i data-lucide="plus"></i> Новое сообщение</button>
|
||||
</div>
|
||||
<div class="digest-layout">
|
||||
<aside class="digest-side">
|
||||
<div class="digest-side-head">
|
||||
<span class="digest-side-title">Сообщения</span>
|
||||
<span id="digestCount" class="digest-count"></span>
|
||||
</div>
|
||||
<span id="digestCount" class="digest-count"></span>
|
||||
</div>
|
||||
<div class="digest-side-search">
|
||||
<div class="digest-search">
|
||||
<i data-lucide="search"></i>
|
||||
<input type="search" id="digestSearch" placeholder="Поиск по сообщениям" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<div id="digestNav" class="digest-nav"></div>
|
||||
</aside>
|
||||
<div id="digestList" class="digest-list"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+75
-1
@@ -9,6 +9,8 @@
|
||||
let previewRemoved = false;
|
||||
let previewFile = null;
|
||||
let digestImages = [];
|
||||
let activeDigestId = null;
|
||||
let digestNavObserver = null;
|
||||
const DRAFT_KEY = 'whatido:digest:draft';
|
||||
|
||||
function draftPayload() {
|
||||
@@ -206,6 +208,58 @@
|
||||
: (digests.length ? 'Сообщений: ' + digests.length : '');
|
||||
}
|
||||
|
||||
function digestNavItemHtml(d) {
|
||||
const pinned = !!d.is_pinned;
|
||||
return '<button type="button" class="digest-nav-item' + (pinned ? ' is-pinned' : '') + '" data-scroll="' + d.id + '">' +
|
||||
'<span class="digest-nav-title">' + (pinned ? '<i data-lucide="pin"></i>' : '') + esc(d.title) + '</span>' +
|
||||
'<span class="digest-nav-date">' + esc(fmtDateTimeY(d.published_at || d.created_at)) + '</span>' +
|
||||
'</button>';
|
||||
}
|
||||
|
||||
function setActiveDigestNav(id, scrollIntoView) {
|
||||
activeDigestId = id;
|
||||
const items = document.querySelectorAll('#digestNav [data-scroll]');
|
||||
items.forEach(function(el) {
|
||||
const on = Number(el.dataset.scroll) === id;
|
||||
el.classList.toggle('active', on);
|
||||
if (on && scrollIntoView) {
|
||||
const box = el.parentElement;
|
||||
if (box) {
|
||||
const top = el.offsetTop - box.clientHeight / 2 + el.offsetHeight / 2;
|
||||
box.scrollTo({ top: Math.max(0, top), behavior: 'smooth' });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function observeDigestCards() {
|
||||
if (digestNavObserver) { digestNavObserver.disconnect(); digestNavObserver = null; }
|
||||
const cards = document.querySelectorAll('#digestList .digest-card');
|
||||
if (!cards.length || typeof IntersectionObserver === 'undefined') return;
|
||||
digestNavObserver = new IntersectionObserver(function(entries) {
|
||||
const visible = entries.filter(function(e) { return e.isIntersecting; });
|
||||
if (!visible.length) return;
|
||||
visible.sort(function(a, b) { return a.boundingClientRect.top - b.boundingClientRect.top; });
|
||||
setActiveDigestNav(Number(visible[0].target.dataset.id), false);
|
||||
}, { rootMargin: '-15% 0px -65% 0px', threshold: 0 });
|
||||
cards.forEach(function(c) { digestNavObserver.observe(c); });
|
||||
}
|
||||
|
||||
function renderDigestNav(list) {
|
||||
const el = document.getElementById('digestNav');
|
||||
if (!el) return;
|
||||
if (!list.length) {
|
||||
if (digestNavObserver) { digestNavObserver.disconnect(); digestNavObserver = null; }
|
||||
el.innerHTML = '<div class="digest-nav-empty">' + (digests.length ? 'Ничего не найдено' : 'Сообщений пока нет') + '</div>';
|
||||
activeDigestId = null;
|
||||
return;
|
||||
}
|
||||
el.innerHTML = list.map(digestNavItemHtml).join('');
|
||||
const ids = list.map(function(d) { return d.id; });
|
||||
setActiveDigestNav(ids.indexOf(activeDigestId) === -1 ? list[0].id : activeDigestId, false);
|
||||
observeDigestCards();
|
||||
}
|
||||
|
||||
function renderDigests() {
|
||||
const el = document.getElementById('digestList');
|
||||
if (!el) return;
|
||||
@@ -218,6 +272,7 @@
|
||||
'<p class="sub">Опубликуйте важное объявление — его увидят все тьюторы и админы.</p>' +
|
||||
(isAdmin() ? '<button type="button" class="btn-primary" data-action="new"><i data-lucide="plus"></i>Создать сообщение</button>' : '') +
|
||||
'</div>';
|
||||
renderDigestNav([]);
|
||||
renderIcons();
|
||||
return;
|
||||
}
|
||||
@@ -225,10 +280,12 @@
|
||||
el.innerHTML = '<div class="digest-empty"><i data-lucide="search-x"></i>' +
|
||||
'<p>Ничего не найдено</p>' +
|
||||
'<p class="sub">По запросу «' + esc(query.trim()) + '» сообщений нет</p></div>';
|
||||
renderDigestNav([]);
|
||||
renderIcons();
|
||||
return;
|
||||
}
|
||||
el.innerHTML = list.map(digestCardHtml).join('');
|
||||
renderDigestNav(list);
|
||||
renderIcons();
|
||||
}
|
||||
|
||||
@@ -238,6 +295,11 @@
|
||||
el.innerHTML = '<div class="digest-empty error"><i data-lucide="wifi-off"></i>' +
|
||||
'<p>Не удалось загрузить сообщения</p>' +
|
||||
'<button type="button" class="btn-primary ghost" data-action="reload">Повторить</button></div>';
|
||||
const nav = document.getElementById('digestNav');
|
||||
if (nav) {
|
||||
if (digestNavObserver) { digestNavObserver.disconnect(); digestNavObserver = null; }
|
||||
nav.innerHTML = '<div class="digest-nav-empty">Не удалось загрузить</div>';
|
||||
}
|
||||
renderIcons();
|
||||
}
|
||||
|
||||
@@ -678,6 +740,18 @@
|
||||
document.getElementById('digestNewBtn').addEventListener('click', function() { openDigestModal(null); });
|
||||
const search = document.getElementById('digestSearch');
|
||||
if (search) search.addEventListener('input', function() { query = search.value; renderDigests(); });
|
||||
document.addEventListener('click', function(e) {
|
||||
const nav = e.target.closest('#digestNav [data-scroll]');
|
||||
if (!nav) return;
|
||||
const id = parseInt(nav.dataset.scroll, 10);
|
||||
const card = document.querySelector('#digestList .digest-card[data-id="' + id + '"]');
|
||||
if (!card) return;
|
||||
setActiveDigestNav(id, true);
|
||||
card.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
card.classList.add('digest-highlight');
|
||||
clearTimeout(card._hlTimer);
|
||||
card._hlTimer = setTimeout(function() { card.classList.remove('digest-highlight'); }, 1600);
|
||||
});
|
||||
document.addEventListener('click', async function(e) {
|
||||
const actEl = e.target.closest('[data-action]');
|
||||
if (actEl) {
|
||||
@@ -731,7 +805,7 @@
|
||||
if (admin || mine) openDigestModal(d);
|
||||
else {
|
||||
const card = document.querySelector('[data-page="digest"] .digest-card[data-id="' + id + '"]');
|
||||
if (card) { card.scrollIntoView({ behavior: 'smooth', block: 'center' }); card.classList.add('digest-highlight'); setTimeout(function() { card.classList.remove('digest-highlight'); }, 1500); }
|
||||
if (card) { setActiveDigestNav(id, true); card.scrollIntoView({ behavior: 'smooth', block: 'center' }); card.classList.add('digest-highlight'); setTimeout(function() { card.classList.remove('digest-highlight'); }, 1500); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user