// Archive — список вопросов с фильтром по категориям и избранному // Changes from v1: // - "В избранное (в боте)" заменён на настоящий toggle /api/couple/favorite // - Добавлен фильтр «⭐ Избранное» (показывает только favorite=true) window.ArchiveScreen = function ArchiveScreen({ setScreen, data, reload }) { const { useState } = React; const D = data; const [filter, setFilter] = useState('all'); const [openId, setOpenId] = useState(D.history.length ? D.history[0].id : null); const [copiedId, setCopiedId] = useState(null); const [busyId, setBusyId] = useState(null); // Local favorite overrides (optimistic) const [favOverrides, setFavOverrides] = useState({}); function isFav(item) { if (favOverrides[item.id] !== undefined) return favOverrides[item.id]; return !!item.favorite; } const filtered = filter === 'all' ? D.history : filter === '_favorites' ? D.history.filter(h => isFav(h)) : D.history.filter(h => h.category === filter); const presentCats = {}; D.history.forEach(h => { presentCats[h.category] = (presentCats[h.category] || 0) + 1; }); const favCount = D.history.filter(h => isFav(h)).length; if (!D.history.length) { return (

Архив вопросов

Пока пусто — ответьте на первый вопрос вместе
📖
Здесь появятся вопросы, на которые вы оба ответили.
); } const h = D.history.find(x => x.id === openId) || D.history[0]; const dcat = h.cat_meta; const hFav = isFav(h); function copy(text) { try { navigator.clipboard && navigator.clipboard.writeText(text); setCopiedId(h.id); setTimeout(() => setCopiedId(null), 1500); } catch (e) { /* ignore */ } } async function toggleFavorite(item) { if (busyId) return; const prev = isFav(item); const next = !prev; setFavOverrides(o => ({ ...o, [item.id]: next })); setBusyId(item.id); try { await window.API.setFavorite(item.db_id || item.id, next); if (reload) reload(); } catch (e) { setFavOverrides(o => ({ ...o, [item.id]: prev })); alert('Не удалось сохранить: ' + (e.message || 'ошибка')); } finally { setBusyId(null); } } // Filter row: "Все", categories present in history, "⭐ Избранное" const chips = [ { key: 'all', meta: { ru: 'Все', emoji: '🗂', color: 'var(--text-2)' }, count: D.history.length }, ...Object.keys(presentCats).map(c => ({ key: c, meta: D.cats[c] || D.cats._default, count: presentCats[c] || 0 })), { key: '_favorites', meta: { ru: 'Избранное', emoji: '⭐', color: 'oklch(0.8 0.18 70)' }, count: favCount } ]; return (

Архив вопросов

{D.history.length} {D.history.length === 1 ? 'ответ' : (D.history.length < 5 ? 'ответа' : 'ответов')} · с {D.pair.started_at}
{chips.map(c => { const active = filter === c.key; return ( ); })}
{filtered.length ? filtered.map(item => { const cat = item.cat_meta; const isOpen = h.id === item.id; const fav = isFav(item); return ( ); }) : (
{filter === '_favorites' ? 'Пока нет избранных вопросов' : 'В этой категории пока пусто'}
)}
#{h.number} · {h.date} {dcat.emoji} {dcat.ru} {hFav && ⭐ в избранном}

«{h.text}»

{D.me.name}
{h.you || }
{D.partner.name}
{h.partner || }
{(h.you_reaction || h.partner_reaction) && (
{h.you_reaction && Вы: {h.you_reaction}} {h.partner_reaction && {D.partner.name}: {h.partner_reaction}}
)}
); };