Доработать UI до MVP

This commit is contained in:
AidarKC
2026-10-10 13:23:26 +03:00
parent e14e3dfa21
commit d138bd9464
8 changed files with 114 additions and 4 deletions
+19 -1
View File
@@ -1,3 +1,4 @@
import { mountPublicChannelSidebar } from '../services/public-channel-sidebar.js';
import { confirmDialog } from '../components/confirm-dialog.js';
import { iconHtml } from '../components/ui-icon.js';
import { rememberChannelPosition, readChannelPosition, restoreChannelPosition } from '../services/channel-view-state.js';
@@ -1617,7 +1618,7 @@ export function render({ navigate, route, chrome }) {
try {
let resolvedMessage = selector.message;
if (selector.short?.ownerBlockchainName && selector.short?.channelName) {
const ownFeed = await authService.listSubscriptionsFeed(state.session.login, 1000);
const ownFeed = state.session.isAuthorized ? await authService.listSubscriptionsFeed(state.session.login, 1000) : {};
if (disposed || seq !== refreshSeq) return;
const allRows = [
...(Array.isArray(ownFeed?.ownedChannels) ? ownFeed.ownedChannels : []),
@@ -1666,6 +1667,17 @@ export function render({ navigate, route, chrome }) {
// ignore owner feed lookup errors
}
}
if (!channel && ownerLoginFromBch) {
try {
const publicChannels = await authService.listUserProfileChannels(ownerLoginFromBch, 'owned', 500, 0, true);
const row = (Array.isArray(publicChannels?.channels) ? publicChannels.channels : []).find((item) =>
String(item?.slug || '').trim().toLowerCase() === channelNameNormalized);
if (row) channel = { channel: {
ownerBlockchainName: row.ownerBlockchainName,
channelRoot: { blockNumber: Number(row.rootBlockNumber), blockHash: normalizeRouteHash(row.rootBlockHashHex) },
} };
} catch { /* Public profile may be unavailable. */ }
}
const ownerBch = String(channel?.channel?.ownerBlockchainName || '').trim();
const rootNo = Number(channel?.channel?.channelRoot?.blockNumber);
const rootHash = normalizeRouteHash(channel?.channel?.channelRoot?.blockHash);
@@ -1732,6 +1744,12 @@ export function render({ navigate, route, chrome }) {
clearContent();
const channelOwner = extractLoginFromBlockchainName(selector?.channel?.ownerBlockchainName || focus?.channelInfo?.ownerBlockchainName || '');
if (!state.session.isAuthorized) mountPublicChannelSidebar(screen, {
owner: channelOwner,
channel: resolvedChannelTitle,
subscribers: payload?.channel?.subscribersCount ?? payload?.focus?.channelInfo?.subscribersCount ?? null,
navigate,
});
const openPost = () => {
const routeToChannel = buildChannelRouteFromThread(selector, resolvedChannelLabel);
if (routeToChannel) navigate(routeToChannel);
+28
View File
@@ -1,3 +1,4 @@
import { mountPublicChannelSidebar } from '../services/public-channel-sidebar.js';
import { confirmDialog } from '../components/confirm-dialog.js';
import { iconHtml } from '../components/ui-icon.js';
import { rememberChannelPosition, readChannelPosition, restoreChannelPosition } from '../services/channel-view-state.js';
@@ -41,6 +42,7 @@ import {
extractLoginFromBlockchainName,
makeProfileRoute,
makeShineMessageRoute,
makeShineChannelStreamRoute,
makeShineChannelAboutRoute,
makeShineChannelDonateRoute,
} from '../services/shine-routes.js';
@@ -243,6 +245,8 @@ function buildThreadRoute(messageRef, selector) {
ownerLogin,
messageBlockchainName: messageRef.blockchainName,
messageBlockNumber: messageRef.blockNumber,
channelName: selector.channelName,
channelOwnerBlockchainName: selector.ownerBlockchainName,
});
}
@@ -2136,6 +2140,14 @@ function renderPostCard(post, {
// Порядок как в макете V4: лайк → поделиться → обсуждение; дата и «⋯» — справа
actions.append(likeButton, shareButton, discussionButton);
if (post.messageRef?.blockNumber != null) {
const streamRoute = makeShineChannelStreamRoute({
ownerBlockchainName: selector?.ownerBlockchainName,
channelName: selector?.channelName || '',
messageBlockNumber: post.messageRef.blockNumber,
});
if (streamRoute) menuItems.unshift({ label: 'Ссылка на сообщение в ленте', iconHtml: iconHtml('share'), action: () => onShare(streamRoute) });
}
menuItems.unshift({ label: 'Ответить', iconHtml: iconHtml('reply'), action: () => replyButton.click() });
if (post.msgSubType === MSG_SUBTYPE_TEXT_REPOST && post.targetRef?.blockchainName && Number.isFinite(post.targetRef?.blockNumber) && post.targetRef?.blockHash) {
const originalBtn = document.createElement('button');
@@ -2368,6 +2380,14 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
screen.append(feed);
}
const requestedBlock = String(handlers.scrollToMessageBlockNumber || '').trim();
if (/^[0-9]+$/.test(requestedBlock)) {
const card = [...screen.querySelectorAll('.channel-message-card[data-message-key]')].find((el) => {
const parts = String(el.dataset.messageKey || '').split(':');
return parts.length >= 3 && parts[parts.length - 2] === requestedBlock;
});
if (card) pendingScrollByRoute.set(routeKey, card.dataset.messageKey);
}
const hasPendingScrollTarget = pendingScrollByRoute.has(routeKey);
const restorePosition = handlers.restorePosition;
const pendingScrollTimer = Number.isFinite(restorePosition) && !hasPendingScrollTarget ? 0 : applyPendingScroll(screen, routeKey, channelData.isOwnChannel || channelData.isDiary || unreadCount === 0);
@@ -2442,12 +2462,14 @@ function renderSkeleton(screen) {
export function render({ navigate, route, chrome }) {
const channelId = route.params.channelId || '';
const scrollToMessageBlockNumber = route.params.scrollToMessageBlockNumber || '';
const routeSelector = buildSelectorFromRoute(route, channelId);
const routeKey = `${routeSelector?.ownerBlockchainName || ''}:${routeSelector?.channelRootBlockNumber || ''}:${routeSelector?.channelRootBlockHash || ''}`;
const screen = document.createElement('section');
screen.className = 'stack channels-screen channels-screen--channel';
const positionKey = `${state.session.login}:channel:${routeKey}`;
// A deep link must take precedence over a saved scroll position.
let disposed = false;
let refreshSeq = 0;
@@ -2963,6 +2985,7 @@ export function render({ navigate, route, chrome }) {
};
}
activeChannelData = apiData;
if (channelMoreButton) {
channelMoreButton.disabled = false;
}
@@ -2982,6 +3005,7 @@ export function render({ navigate, route, chrome }) {
cleanupSeenTracking = renderBody(screen, navigate, routeKey, apiData, {
chrome,
restorePosition,
scrollToMessageBlockNumber,
showStatus,
isActive: () => !disposed,
onAddMessage: activeAddMessage = async () => {
@@ -3072,6 +3096,10 @@ export function render({ navigate, route, chrome }) {
},
onSubscribeChannel: (event) => subscribeToChannel(apiData, event),
});
if (!state.session.isAuthorized && !apiData?.isDiary) mountPublicChannelSidebar(screen, {
owner: apiData?.channel?.ownerName || extractLoginFromBlockchainName(apiData?.selector?.ownerBlockchainName),
channel: titleLabel, subscribers: apiData?.channel?.subscribersCount, navigate,
});
} catch (error) {
if (disposed || seq !== refreshSeq) return;
skeleton?.remove();