SHA256
UI: редактор ответа и записи – поле сразу под именем, «прикрепить» в нижней панели, миниатюры
Текст пишется в колонке справа от аватара сразу под именем (и строкой «В канал …»), без пустого места; «прикрепить» – слева в нижней панели, «Очистить» – в шапке, пока есть текст или вложения; счётчик символов показывается только с 1500 знаков. Картинки и видео во вложениях – миниатюрами с крестиком (видео со значком воспроизведения), прочие файлы – строкой. Нижняя панель на flex: на 320 px ничего не выходит за край, выбор типа записи сжимается.
This commit is contained in:
@@ -6,6 +6,7 @@ import { state } from '../state.js';
|
||||
import { toUserMessage } from '../services/ui-error-texts.js';
|
||||
import { renderUserAvatar } from './avatar-image.js';
|
||||
import { openAuthRequiredModal } from '../services/auth-required-modal.js';
|
||||
import { resolvePublicFileUrl } from '../services/public-file-service.js';
|
||||
|
||||
const drafts = new Map();
|
||||
|
||||
@@ -14,6 +15,24 @@ function draftKey(key) {
|
||||
return `${login}:${String(key || 'editor')}`;
|
||||
}
|
||||
|
||||
// Превью вложения в редакторе: картинки и видео – миниатюрой (как в Threads), остальное – строкой с именем.
|
||||
const previewUrls = new Map();
|
||||
function attachmentKind(item) {
|
||||
const name = String(item?.name || '').toLowerCase();
|
||||
if (/\.(jpe?g|png|gif|webp|avif|heic|bmp)$/.test(name)) return 'image';
|
||||
if (/\.(mp4|webm|mov|m4v|ogv)$/.test(name)) return 'video';
|
||||
return 'file';
|
||||
}
|
||||
function attachmentPreviewUrl(item, login) {
|
||||
const key = item?.ar ? `ar:${item.ar}` : `sha:${item?.sha256 || ''}`;
|
||||
if (!previewUrls.has(key)) {
|
||||
previewUrls.set(key, item?.ar
|
||||
? Promise.resolve(`${String(state.entrySettings.arweaveServer || 'https://arweave.net').replace(/\/$/, '')}/${item.ar}`)
|
||||
: resolvePublicFileUrl({ sha256: item?.sha256, authorLogin: login, solanaEndpoint: state.entrySettings.solanaServer, fallbackServerLogin: state.entrySettings.shineServerLogin }).catch(() => ''));
|
||||
}
|
||||
return previewUrls.get(key);
|
||||
}
|
||||
|
||||
function attachmentLabel(item) {
|
||||
const name = String(item?.name || 'Файл');
|
||||
const size = Number(item?.size || 0);
|
||||
@@ -88,7 +107,9 @@ export function openChannelEditor({
|
||||
const draftMark = document.createElement('span');
|
||||
draftMark.className = 'channel-editor__draft';
|
||||
draftMark.textContent = 'Черновик';
|
||||
header.append(closeButton, heading, draftMark);
|
||||
const headerEnd = document.createElement('div');
|
||||
headerEnd.className = 'channel-editor__header-end';
|
||||
header.append(closeButton, heading, headerEnd);
|
||||
|
||||
const body = document.createElement('div');
|
||||
body.className = 'channel-editor__body';
|
||||
@@ -147,6 +168,7 @@ export function openChannelEditor({
|
||||
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.className = 'channel-editor__input';
|
||||
textarea.rows = 1;
|
||||
textarea.maxLength = 2000;
|
||||
textarea.placeholder = placeholder;
|
||||
textarea.setAttribute('aria-label', placeholder);
|
||||
@@ -163,7 +185,7 @@ export function openChannelEditor({
|
||||
const clearButton = document.createElement('button');
|
||||
clearButton.type = 'button';
|
||||
clearButton.className = 'text-btn channel-editor__clear';
|
||||
clearButton.textContent = 'Очистить черновик';
|
||||
clearButton.textContent = 'Очистить';
|
||||
|
||||
const author = document.createElement('div');
|
||||
author.className = 'channel-editor__author';
|
||||
@@ -190,14 +212,13 @@ export function openChannelEditor({
|
||||
attachButton.innerHTML = `${iconHtml('image')}<span class="sr-only">Прикрепить фото, видео или файл</span>`;
|
||||
attachButton.title = 'Фото, видео или файл';
|
||||
attachButton.hidden = !allowAttachments;
|
||||
// Как в Threads: текст пишется прямо под именем, без рамки; под ним – вложения и иконка «прикрепить».
|
||||
// Как в 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);
|
||||
compose.append(textarea, attachmentsBox, error);
|
||||
authorText.append(compose);
|
||||
headerEnd.append(clearButton, draftMark);
|
||||
const counter = document.createElement('span');
|
||||
counter.className = 'channel-editor__counter';
|
||||
const submitButton = document.createElement('button');
|
||||
@@ -205,6 +226,7 @@ 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);
|
||||
@@ -223,15 +245,42 @@ export function openChannelEditor({
|
||||
|
||||
const sync = () => {
|
||||
textarea.style.height = 'auto';
|
||||
textarea.style.height = `${Math.max(48, textarea.scrollHeight)}px`;
|
||||
textarea.style.height = `${Math.max(24, textarea.scrollHeight)}px`;
|
||||
const length = textarea.value.length;
|
||||
counter.textContent = `${length} / 2000`;
|
||||
counter.classList.toggle('is-near-limit', length >= 1800);
|
||||
// Счётчик нужен только у предела, пустой «0 / 2000» лишь шумит.
|
||||
counter.classList.toggle('is-hidden', length < 1500);
|
||||
submitButton.disabled = inFlight || picking || length > textarea.maxLength || (!allowEmptyText && !textarea.value.trim() && attachments.length === 0);
|
||||
dialog.setAttribute('aria-busy', String(inFlight || picking));
|
||||
clearButton.hidden = !textarea.value && attachments.length === 0;
|
||||
draftMark.hidden = !clearButton.hidden;
|
||||
attachmentsBox.replaceChildren();
|
||||
attachments.forEach((item, index) => {
|
||||
const kind = attachmentKind(item);
|
||||
if (kind !== 'file') {
|
||||
const thumb = document.createElement('div');
|
||||
thumb.className = `channel-editor__thumb channel-editor__thumb--${kind}`;
|
||||
thumb.title = attachmentLabel(item);
|
||||
const media = document.createElement(kind === 'image' ? 'img' : 'video');
|
||||
if (kind === 'image') media.alt = String(item?.name || 'Изображение');
|
||||
else { media.muted = true; media.preload = 'metadata'; media.playsInline = true; }
|
||||
void attachmentPreviewUrl(item, login).then((url) => { if (url && media.isConnected !== false) media.src = url; });
|
||||
const remove = document.createElement('button');
|
||||
remove.type = 'button';
|
||||
remove.className = 'channel-editor__thumb-remove';
|
||||
remove.setAttribute('aria-label', `Убрать вложение ${item?.name || ''}`);
|
||||
remove.innerHTML = iconHtml('close');
|
||||
remove.disabled = inFlight;
|
||||
remove.addEventListener('click', () => {
|
||||
attachments.splice(index, 1);
|
||||
saveDraft();
|
||||
sync();
|
||||
});
|
||||
thumb.append(media, remove);
|
||||
attachmentsBox.append(thumb);
|
||||
return;
|
||||
}
|
||||
const card = document.createElement('div');
|
||||
card.className = 'channel-editor__attachment';
|
||||
const label = document.createElement('span');
|
||||
|
||||
Reference in New Issue
Block a user