SHA256
UI: экраны без мелькания – кэш каналов и обсуждений, фоновая подгрузка, заставка как экран входа
- «Назад» при открытом редакторе закрывает только редактор: слой в истории ведёт роутер (openHistoryLayer), экран под ним больше не пересоздаётся. - Канал и обсуждение при возврате рисуются сразу из памяти (page-data-cache), свежие данные подтягиваются тихо и перерисовывают экран, только если что-то изменилось; место в ленте сохраняется. - Раз в минуту, пока вкладка на экране, обновляются лента каналов и шесть самых активных каналов. - Обсуждение начинает грузиться при касании записи или ответа, канал для него берётся из кэша. - Уведомления и профиль при повторном заходе без пустого кадра; убрано проявление списка каналов. - Заглушка – только если загрузка дольше 0,5 с. - Общая карточка «не удалось загрузить»: заголовок, причина в пару строк, крупная кнопка снизу. - Стартовая заставка повторяет экран входа (знак, надпись, раскладка, фаза сияния) – смена незаметна.
This commit is contained in:
@@ -5,6 +5,7 @@ import { toUserMessage } from '../services/ui-error-texts.js';
|
||||
import { parseMessageAttachments } from '../services/attachment-format.js';
|
||||
import {
|
||||
animatePress,
|
||||
createLoadErrorCard,
|
||||
createSkeletonRows,
|
||||
SKELETON_DELAY_MS,
|
||||
formatListTime,
|
||||
@@ -21,6 +22,9 @@ import { createDropdownMenu } from '../components/dropdown-menu.js';
|
||||
import { createTopBar } from '../components/topbar.js';
|
||||
import { parseDmTechBlocks } from '../services/dm-tech-blocks.js';
|
||||
import { rememberChannelPosition, readChannelPosition, restoreChannelPosition } from '../services/channel-view-state.js';
|
||||
import { pageDataAge } from '../services/page-data-cache.js';
|
||||
import { toPrettyPath } from '../router.js';
|
||||
import { prefetchChannelPage } from './channel-view.js';
|
||||
|
||||
export const pageMeta = { id: 'channels-list', title: 'Каналы', shellMode: { scrollbar: 'hidden', topFade: false, contentUnderTopbar: false, contentWidth: 'wide' } };
|
||||
|
||||
@@ -892,6 +896,35 @@ function mapApiFeed(feed, notificationsState, diaryPayload = null) {
|
||||
return { ownChannels, followedUserChannels, subscribedChannels, index };
|
||||
}
|
||||
|
||||
const PREFETCH_CHANNELS = 6;
|
||||
const PREFETCH_FRESH_MS = 50_000;
|
||||
|
||||
// Фоновое обновление ленты каналов и самых активных каналов: экран «Каналы» и сами каналы
|
||||
// открываются сразу из памяти. Запросы идут по одному, чтобы не нагружать сервер.
|
||||
export async function refreshChannelsInBackground({ isCurrent = () => true } = {}) {
|
||||
if (!state.session.isAuthorized || state.session.isLocalDemo) return;
|
||||
const login = state.session.login;
|
||||
const feed = await authService.listSubscriptionsFeed(login, 200);
|
||||
if (!isCurrent() || state.session.login !== login) return;
|
||||
const groups = mapApiFeed(feed, {}, null);
|
||||
setChannelsFeed(feed, groups.index);
|
||||
const routes = toListModel(groups)
|
||||
.filter((row) => row.route)
|
||||
.sort((a, b) => Number(b.lastMessageAt || 0) - Number(a.lastMessageAt || 0))
|
||||
.slice(0, PREFETCH_CHANNELS)
|
||||
.map((row) => `/${toPrettyPath(row.route)}`);
|
||||
for (const route of routes) {
|
||||
if (!isCurrent() || state.session.login !== login) return;
|
||||
const pathname = new URL(route, window.location.origin).pathname;
|
||||
if (pathname === window.location.pathname || pageDataAge('channel', pathname) < PREFETCH_FRESH_MS) continue;
|
||||
try {
|
||||
await prefetchChannelPage(pathname);
|
||||
} catch {
|
||||
// Фоновая подгрузка не должна мешать: канал загрузится обычным путём при открытии.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toListModel(groups) {
|
||||
return [
|
||||
...(groups.ownChannels || []),
|
||||
@@ -923,24 +956,11 @@ function renderSkeletonList(container, count = 4) {
|
||||
}
|
||||
|
||||
function renderErrorState(container, error, onRetry) {
|
||||
const errCard = document.createElement('div');
|
||||
errCard.className = 'card stack channels-status';
|
||||
|
||||
const title = document.createElement('strong');
|
||||
title.textContent = 'Не удалось загрузить каналы';
|
||||
|
||||
const details = document.createElement('p');
|
||||
details.className = 'meta-muted';
|
||||
details.textContent = toUserMessage(error, 'Проверьте подключение к серверу и повторите попытку.');
|
||||
|
||||
const retry = document.createElement('button');
|
||||
retry.className = 'primary-btn';
|
||||
retry.type = 'button';
|
||||
retry.textContent = 'Повторить';
|
||||
retry.addEventListener('click', onRetry);
|
||||
|
||||
errCard.append(title, details, retry);
|
||||
container.append(errCard);
|
||||
container.append(createLoadErrorCard({
|
||||
title: 'Не удалось загрузить каналы',
|
||||
message: toUserMessage(error, 'Проверьте подключение и повторите попытку.'),
|
||||
onRetry,
|
||||
}));
|
||||
}
|
||||
|
||||
function renderDemoFallback(container, navigate, error, onRetry, { localOnly = false } = {}) {
|
||||
@@ -1064,7 +1084,7 @@ function renderListContent({ screen, container, listState, navigate, refreshFeed
|
||||
}
|
||||
|
||||
const list = document.createElement('div');
|
||||
list.className = 'stack channels-groups channels-list-body-fade';
|
||||
list.className = 'stack channels-groups';
|
||||
|
||||
const rerenderList = () => renderListContent({ screen, container, listState, navigate, refreshFeed });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user