SHA256
Доработать согласия и статусы профиля
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { iconHtml } from './ui-icon.js';
|
||||
import { confirmDialog } from './confirm-dialog.js';
|
||||
import { markArweaveAttachmentPlaced } from './arweave-attachment-manager.js';
|
||||
import { openChannelAttachmentManager } from './channel-attachment-manager.js';
|
||||
import { composeMessageWithAttachments, MAX_MESSAGE_ATTACHMENTS } from '../services/attachment-format.js';
|
||||
@@ -339,6 +340,25 @@ export function openChannelEditor({
|
||||
submitButton.textContent = 'Отправляем…';
|
||||
sync();
|
||||
try {
|
||||
const accepted = await confirmDialog({
|
||||
title: 'Записать в публичную историю?',
|
||||
aboveEditor: true,
|
||||
text: 'Эта публикация, ответ или изменение будут записаны в блокчейн. Запись может сохраняться постоянно, включая историю правок и удаления. Если передумали, выберите «Вернуться к черновику».',
|
||||
confirmLabel: 'Да, опубликовать',
|
||||
cancelLabel: 'Вернуться к черновику',
|
||||
});
|
||||
if (!isActive() || closed) return;
|
||||
if (!accepted) {
|
||||
inFlight = false;
|
||||
textarea.disabled = false;
|
||||
attachButton.disabled = false;
|
||||
clearButton.disabled = false;
|
||||
if (extraControl) extraControl.querySelectorAll('select,button,input').forEach((el) => { el.disabled = false; });
|
||||
submitButton.textContent = submitLabel;
|
||||
saveDraft();
|
||||
sync();
|
||||
return;
|
||||
}
|
||||
await onSubmit({
|
||||
text: rawText ? textarea.value.trim() : composeMessageWithAttachments(textarea.value.trim(), attachments),
|
||||
attachments: [...attachments],
|
||||
|
||||
@@ -5,11 +5,12 @@ export function confirmDialog({
|
||||
confirmLabel = 'Да',
|
||||
cancelLabel = 'Отмена',
|
||||
danger = false,
|
||||
aboveEditor = false,
|
||||
} = {}) {
|
||||
return new Promise((resolve) => {
|
||||
const opener = document.activeElement;
|
||||
const modal = document.createElement('div');
|
||||
modal.className = 'modal confirm-dialog';
|
||||
modal.className = `modal confirm-dialog${aboveEditor ? ' confirm-dialog--above-editor' : ''}`;
|
||||
modal.innerHTML = `
|
||||
<div class="modal-card confirm-dialog__card" role="alertdialog" aria-modal="true" aria-labelledby="confirm-dialog-title">
|
||||
<h2 class="modal-title" id="confirm-dialog-title"></h2>
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import { openSheet } from './sheet.js';
|
||||
|
||||
// Пошаговое подтверждение перед публичной записью. Ни один шаг не выполняет сетевых запросов.
|
||||
// Текст задаёт вызывающий экран; запись начинается только после прохождения всех шагов.
|
||||
export function confirmConsentSteps({ title = 'Подтверждение', steps = [] } = {}) {
|
||||
if (!steps.length) return Promise.resolve(false);
|
||||
return new Promise((resolve) => {
|
||||
let completed = false;
|
||||
let stepIndex = 0;
|
||||
const content = document.createElement('div');
|
||||
content.className = 'stack profile-consent-flow';
|
||||
const progress = document.createElement('div');
|
||||
progress.className = 'meta-muted profile-consent-progress';
|
||||
const heading = document.createElement('h3');
|
||||
heading.className = 'profile-consent-heading';
|
||||
const paragraph = document.createElement('p');
|
||||
paragraph.className = 'profile-consent-description';
|
||||
const checkboxLabel = document.createElement('label');
|
||||
checkboxLabel.className = 'profile-consent-accept';
|
||||
const checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
const checkboxText = document.createElement('span');
|
||||
checkboxLabel.append(checkbox, checkboxText);
|
||||
const actions = document.createElement('div');
|
||||
actions.className = 'form-actions-grid';
|
||||
const cancelBtn = document.createElement('button');
|
||||
cancelBtn.type = 'button';
|
||||
cancelBtn.className = 'secondary-btn';
|
||||
cancelBtn.textContent = 'Отмена';
|
||||
const nextBtn = document.createElement('button');
|
||||
nextBtn.type = 'button';
|
||||
nextBtn.className = 'primary-btn';
|
||||
actions.append(cancelBtn, nextBtn);
|
||||
content.append(progress, heading, paragraph, checkboxLabel, actions);
|
||||
|
||||
const sheet = openSheet({
|
||||
title,
|
||||
className: 'profile-consent-sheet',
|
||||
content,
|
||||
onClose: () => resolve(completed),
|
||||
});
|
||||
function renderStep() {
|
||||
const step = steps[stepIndex];
|
||||
progress.textContent = `${stepIndex + 1} / ${steps.length}`;
|
||||
heading.textContent = step.title;
|
||||
paragraph.textContent = step.text;
|
||||
checkbox.checked = false;
|
||||
checkboxLabel.hidden = !step.accept;
|
||||
checkboxText.textContent = step.accept || '';
|
||||
nextBtn.disabled = Boolean(step.accept);
|
||||
nextBtn.textContent = step.button || (stepIndex === steps.length - 1 ? 'Подтверждаю и продолжаю' : 'Понятно, дальше');
|
||||
}
|
||||
checkbox.addEventListener('change', () => { nextBtn.disabled = !checkbox.checked; });
|
||||
cancelBtn.addEventListener('click', () => sheet.close());
|
||||
nextBtn.addEventListener('click', () => {
|
||||
if (steps[stepIndex].accept && !checkbox.checked) return;
|
||||
if (stepIndex === steps.length - 1) {
|
||||
completed = true;
|
||||
sheet.close();
|
||||
} else {
|
||||
stepIndex += 1;
|
||||
renderStep();
|
||||
}
|
||||
});
|
||||
renderStep();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { openSheet } from './sheet.js';
|
||||
|
||||
function safeCount(raw, maximum = Infinity) {
|
||||
const count = Number(raw);
|
||||
return Number.isFinite(count) ? Math.max(0, Math.min(maximum, Math.trunc(count))) : 0;
|
||||
}
|
||||
|
||||
// Значения счётчиков получены от сервера, это не криптографическая аттестация личности.
|
||||
export function confirmLikeAction({ liked = false, counts = {}, onViewList = null } = {}) {
|
||||
return new Promise((resolve) => {
|
||||
let accepted = false;
|
||||
const all = safeCount(counts.all ?? counts.likesCount);
|
||||
const official = safeCount(counts.official ?? counts.primaryLikesCount, all);
|
||||
const shining = safeCount(counts.shining ?? counts.shiningLikesCount, official);
|
||||
const body = document.createElement('div');
|
||||
body.className = 'stack like-consent';
|
||||
const intro = document.createElement('p');
|
||||
intro.textContent = 'Лайки этого сообщения (по данным сервера):';
|
||||
const grid = document.createElement('div');
|
||||
grid.className = 'like-consent-counters';
|
||||
const categories = [
|
||||
{ label: 'Официальные сияющие', count: shining, type: 'shining' },
|
||||
{ label: 'Все официальные', count: official, type: 'official' },
|
||||
{ label: 'Все аккаунты', count: all, type: 'all' },
|
||||
];
|
||||
categories.forEach(({ label, count, type }) => {
|
||||
const item = document.createElement(onViewList ? 'button' : 'div');
|
||||
item.className = 'like-consent-count';
|
||||
if (onViewList) {
|
||||
item.type = 'button';
|
||||
item.addEventListener('click', () => {
|
||||
sheet.close();
|
||||
onViewList(type);
|
||||
});
|
||||
}
|
||||
const number = document.createElement('strong');
|
||||
number.textContent = String(count);
|
||||
const name = document.createElement('span');
|
||||
name.textContent = label;
|
||||
item.append(number, name);
|
||||
grid.append(item);
|
||||
});
|
||||
const warning = document.createElement('p');
|
||||
warning.className = 'meta-muted';
|
||||
warning.textContent = 'Добавление и отмена лайка создают записи в публичной истории блокчейна. Даже отменённый лайк может остаться в истории.';
|
||||
const actions = document.createElement('div');
|
||||
actions.className = 'form-actions-grid';
|
||||
const cancel = document.createElement('button');
|
||||
cancel.type = 'button';
|
||||
cancel.className = 'secondary-btn';
|
||||
cancel.textContent = 'Не менять';
|
||||
const confirm = document.createElement('button');
|
||||
confirm.type = 'button';
|
||||
confirm.className = 'primary-btn';
|
||||
confirm.textContent = liked ? 'Убрать мой лайк' : 'Добавить мой лайк';
|
||||
actions.append(cancel, confirm);
|
||||
body.append(intro, grid, warning, actions);
|
||||
const sheet = openSheet({ title: 'Лайки', className: 'like-consent-sheet', content: body, onClose: () => resolve(accepted) });
|
||||
cancel.addEventListener('click', () => sheet.close());
|
||||
confirm.addEventListener('click', () => { accepted = true; sheet.close(); });
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user