// 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 (