UI: четыре кнопки как в Threads, строка ответа и редактор по их образцу

Под записями и ответами – лайк, ответы, репост, поделиться. Репост в блокчейне
ещё дорабатывается: кнопка на месте и пока сообщает «Репосты скоро появятся»
(переключатель REPOSTS_ENABLED в channels-ux.js).
Строка ответа внизу обсуждения: аватар, «Ответьте …», «фото/файл» (редактор
сразу с выбором файла) и «развернуть».
Редактор: текст пишется прямо под именем, без рамки; под текстом – иконка
вложения и «Очистить черновик»; внизу – счётчик и кнопка отправки.
This commit is contained in:
q
2026-10-11 23:05:43 +03:00
parent 7ac9e5a806
commit e6937cb49c
9 changed files with 123 additions and 43 deletions
+14 -6
View File
@@ -36,6 +36,7 @@ export function openChannelEditor({
allowEmptyText = false,
allowAttachments = true,
rawText = false,
openAttachOnStart = false,
onSubmit,
isActive = () => true,
} = {}) {
@@ -180,16 +181,23 @@ export function openChannelEditor({
author.append(authorText);
if (chain.length) author.classList.add('is-chained');
body.append(author);
body.append(textarea, attachmentsBox, error, clearButton);
const footer = document.createElement('footer');
footer.className = 'channel-editor__footer';
const attachButton = document.createElement('button');
attachButton.type = 'button';
attachButton.className = 'secondary-btn channel-editor__attach';
attachButton.innerHTML = `${iconHtml('clip')}<span class="sr-only">Прикрепить</span>`;
attachButton.title = 'Прикрепить файл';
attachButton.className = 'icon-btn channel-editor__attach';
attachButton.innerHTML = `${iconHtml('image')}<span class="sr-only">Прикрепить фото, видео или файл</span>`;
attachButton.title = 'Фото, видео или файл';
attachButton.hidden = !allowAttachments;
// Как в Threads: текст пишется прямо под именем, без рамки; под ним – вложения и иконка «прикрепить».
const compose = document.createElement('div');
compose.className = 'channel-editor__compose';
const tools = document.createElement('div');
tools.className = 'channel-editor__tools';
tools.append(attachButton, clearButton);
compose.append(textarea, attachmentsBox, tools, error);
body.append(compose);
const counter = document.createElement('span');
counter.className = 'channel-editor__counter';
const submitButton = document.createElement('button');
@@ -197,7 +205,6 @@ export function openChannelEditor({
submitButton.className = 'primary-btn channel-editor__submit';
submitButton.textContent = submitLabel;
submitButton.title = 'Отправить · Ctrl+Enter / ⌘+Enter';
footer.append(attachButton);
if (extraControl instanceof Node) {
footer.classList.add('has-extra');
footer.append(extraControl);
@@ -216,7 +223,7 @@ export function openChannelEditor({
const sync = () => {
textarea.style.height = 'auto';
textarea.style.height = `${Math.max(160, textarea.scrollHeight)}px`;
textarea.style.height = `${Math.max(48, textarea.scrollHeight)}px`;
const length = textarea.value.length;
counter.textContent = `${length} / 2000`;
counter.classList.toggle('is-near-limit', length >= 1800);
@@ -409,6 +416,7 @@ export function openChannelEditor({
sync();
if (chain.length) body.scrollTop = author.offsetTop - body.offsetTop - 120;
textarea.focus({ preventScroll: chain.length > 0 });
if (openAttachOnStart && allowAttachments) attachButton.click();
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
});
return { close };
+2
View File
@@ -44,6 +44,8 @@ const paths = {
refresh: '<path d="M20 12a8 8 0 1 1-2.3-5.6"/><path d="M20 4v4.4h-4.4"/>',
eye: '<path d="M2.5 12S6 5.5 12 5.5 21.5 12 21.5 12 18 18.5 12 18.5 2.5 12 2.5 12Z"/><circle cx="12" cy="12" r="3"/>',
eyeOff: '<path d="M10.2 5.7A9.6 9.6 0 0 1 12 5.5c6 0 9.5 6.5 9.5 6.5a16.4 16.4 0 0 1-2.6 3.4M6.4 7A16.2 16.2 0 0 0 2.5 12S6 18.5 12 18.5a9 9 0 0 0 4.9-1.4"/><path d="M9.9 9.9a3 3 0 0 0 4.2 4.2M3.5 3.5l17 17"/>',
repost: '<path d="M17 2.5 20.5 6 17 9.5"/><path d="M3.5 11.5V9a3 3 0 0 1 3-3h14"/><path d="M7 21.5 3.5 18 7 14.5"/><path d="M20.5 12.5V15a3 3 0 0 1-3 3h-14"/>',
expand: '<path d="M14 4h6v6M10 20H4v-6M20 4l-6.5 6.5M4 20l6.5-6.5"/>',
clip: '<path d="m20.5 11.5-8.2 8.2a5 5 0 0 1-7.1-7.1l8.5-8.5a3.3 3.3 0 0 1 4.7 4.7l-8.5 8.5a1.7 1.7 0 0 1-2.4-2.4l7.8-7.8"/>',
};
+56 -13
View File
@@ -13,6 +13,8 @@ import {
formatPostStamp,
formatShortAge,
formatRelativeTime,
notifyRepostSoon,
REPOSTS_ENABLED,
longPressFeel,
shareOrCopyLink,
showToast,
@@ -932,7 +934,20 @@ function renderNodeCard(node, heading, handlers, localNumber, { focusPost = fals
else handlers.onOpenThread(target);
});
// Тот же вид и порядок кнопок, что в ленте канала.
if (threadsLayout) actions.append(likeButton, discussionButton, shareButton);
const repostButton = document.createElement('button');
repostButton.type = 'button';
repostButton.className = 'ui-button channel-action-item channel-action-repost';
repostButton.innerHTML = `
<span class="channel-action-icon" aria-hidden="true">${iconHtml('repost')}</span>
<span class="channel-action-label">Репост</span>
`;
setActionTitle(repostButton, 'Репост');
repostButton.addEventListener('click', (event) => {
event.stopPropagation();
if (!REPOSTS_ENABLED) { notifyRepostSoon(); return; }
void handlers.onRepost?.(target);
});
if (threadsLayout) actions.append(likeButton, discussionButton, repostButton, shareButton);
else actions.append(likeButton, shareButton, discussionButton);
menuItems.unshift({ label: 'Ответить', iconHtml: iconHtml('reply'), action: () => replyButton.click() });
// Те же действия, что у ответов в обсуждении.
@@ -1189,8 +1204,15 @@ function renderComment({ node, parent, focus, channelOwner, handlers, nested = f
share.setAttribute('aria-label', 'Поделиться комментарием');
share.addEventListener('click', () => handlers.shareComment(node));
// Ряд действий как у записи канала: лайк, ответы, поделиться.
actions.append(like, reply, share);
const repost = document.createElement('button');
repost.type = 'button';
repost.className = 'channel-action-item thread-comment__repost';
repost.innerHTML = iconHtml('repost');
repost.setAttribute('aria-label', 'Репост');
repost.addEventListener('click', () => (REPOSTS_ENABLED ? handlers.onRepost?.(target) : notifyRepostSoon()));
// Ряд действий как у записи канала: лайк, ответы, репост, поделиться.
actions.append(like, reply, repost, share);
main.append(actions);
item.append(who, main);
// Как в Threads: нажатие на ответ открывает его обсуждение (кнопки, ссылки и вложения работают сами по себе).
@@ -1993,7 +2015,7 @@ export function render({ navigate, route, chrome }) {
}
return item;
};
replyEditorOpener = (node) => {
replyEditorOpener = (node, { attach = false } = {}) => {
if (!node || disposed) return;
const path = [];
for (let cur = node; cur && cur !== focus; cur = parentByKey.get(nodeKey(cur))) path.unshift(cur);
@@ -2005,6 +2027,7 @@ export function render({ navigate, route, chrome }) {
placeholder: `Ответить ${node.authorLogin || ''}…`,
context: { chain },
key: `thread-reply:${nodeKey(node)}`,
openAttachOnStart: attach,
isActive: () => !disposed,
onSubmit: ({ text }) => handlers.onReply(buildTargetFromNode(node), text),
});
@@ -2016,17 +2039,37 @@ export function render({ navigate, route, chrome }) {
if (focus) {
const bar = document.createElement('div');
bar.className = 'channel-composer thread-composer';
const open = document.createElement('button');
open.type = 'button';
const open = document.createElement('div');
if (state.session.isAuthorized) {
open.className = 'channel-compose-bar';
open.innerHTML = `<span class="channel-compose-bar__text"></span><span class="channel-compose-bar__icon" aria-hidden="true">${iconHtml('send')}</span>`;
open.querySelector('.channel-compose-bar__text').textContent = `Ответить ${focus.authorLogin || ''}…`;
open.addEventListener('click', () => replyEditorOpener(focus));
// Строка ответа как в Threads: аватар, «Ответьте …», прикрепить, развернуть – всё ведёт в общий редактор.
open.className = 'thread-reply-bar';
const me = renderUserAvatar({ login: state.session.login, size: 'xs', className: 'thread-reply-bar__avatar' });
const field = document.createElement('button');
field.type = 'button';
field.className = 'thread-reply-bar__field';
field.textContent = `Ответьте ${focus.authorLogin || ''}…`;
field.addEventListener('click', () => replyEditorOpener(focus));
const attach = document.createElement('button');
attach.type = 'button';
attach.className = 'thread-reply-bar__icon';
attach.innerHTML = iconHtml('image');
attach.setAttribute('aria-label', 'Ответ с фото, видео или файлом');
attach.addEventListener('click', () => replyEditorOpener(focus, { attach: true }));
const expand = document.createElement('button');
expand.type = 'button';
expand.className = 'thread-reply-bar__icon';
expand.innerHTML = iconHtml('expand');
expand.setAttribute('aria-label', 'Открыть редактор ответа');
expand.addEventListener('click', () => replyEditorOpener(focus));
open.append(me, field, attach, expand);
} else {
open.className = 'primary-btn channel-main-action';
open.textContent = 'Войти, чтобы ответить';
open.addEventListener('click', () => { state.authReturnHash = window.location.pathname || '/channels'; navigate('login-view'); });
const loginBtn = document.createElement('button');
loginBtn.type = 'button';
open.append(loginBtn);
open.className = 'thread-reply-guest';
loginBtn.className = 'primary-btn channel-main-action';
loginBtn.textContent = 'Войти, чтобы ответить';
loginBtn.addEventListener('click', () => { state.authReturnHash = window.location.pathname || '/channels'; navigate('login-view'); });
}
bar.append(open);
chrome?.setComposer(bar);
+17 -1
View File
@@ -22,6 +22,8 @@ import {
formatRelativeTime,
formatShortAge,
longPressFeel,
notifyRepostSoon,
REPOSTS_ENABLED,
shareOrCopyLink,
showToast,
softHaptic,
@@ -2165,7 +2167,21 @@ function renderPostCard(post, {
// Порядок как в макете V4: лайк → поделиться → обсуждение; дата и «⋯» — справа.
// В раскладке Threads: лайк → обсуждение → поделиться, дата и «⋯» в шапке.
if (threadsLayout) actions.append(likeButton, discussionButton, shareButton);
const repostButton = document.createElement('button');
repostButton.type = 'button';
repostButton.className = 'ui-button channel-action-item channel-action-repost';
repostButton.innerHTML = `
<span class="channel-action-icon" aria-hidden="true">${iconHtml('repost')}</span>
<span class="channel-action-label">Репост</span>
`;
setActionTitle(repostButton, 'Репост');
repostButton.addEventListener('click', (event) => {
event.stopPropagation();
if (!REPOSTS_ENABLED) { notifyRepostSoon(); return; }
void onRepost?.(post.messageRef);
});
// Четыре кнопки как в Threads: лайк, ответы, репост, поделиться.
if (threadsLayout) actions.append(likeButton, discussionButton, repostButton, shareButton);
else actions.append(likeButton, shareButton, discussionButton);
if (selector?.publicOrdinalUrlsAllowed && post.messageRef?.blockNumber != null) {
const streamRoute = makeShineChannelStreamRoute({
+7
View File
@@ -292,3 +292,10 @@ export async function longPressFeel(el, delayMs = 130) {
await new Promise((resolve) => setTimeout(resolve, Math.max(60, Number(delayMs) || 130)));
if (node) node.classList.remove('is-long-press');
}
// Репост в блокчейне ещё дорабатывается (обещан скоро) – кнопка уже на месте, как четвёртая в ряду действий.
// Когда появится, здесь вызывать настоящий обработчик.
export const REPOSTS_ENABLED = false;
export function notifyRepostSoon() {
showToast('Репосты скоро появятся');
}