SHA256
562 lines
27 KiB
JavaScript
562 lines
27 KiB
JavaScript
import { t, th } from '../i18n/index.js';
|
|
import { createTopBar } from '../components/topbar.js';
|
|
import { confirmDialog } from '../components/confirm-dialog.js';
|
|
import { confirmPublicHistoryAction } from '../services/public-history-consent.js';
|
|
import { confirmConsentSteps } from '../components/consent-steps.js';
|
|
import { actionErrorText, toUserMessage } from '../services/ui-error-texts.js';
|
|
import { showToast } from '../services/channels-ux.js';
|
|
import { profile } from '../mock-data.js';
|
|
import { authService, state } from '../state.js';
|
|
import {
|
|
PROFILE_GENDER_FEMALE,
|
|
PROFILE_GENDER_MALE,
|
|
PROFILE_GENDER_UNKNOWN,
|
|
PROFILE_ACCOUNT_ROLE_PRIMARY,
|
|
PROFILE_ACCOUNT_ROLE_NON_VOTING,
|
|
PROFILE_SHINE_SHINING,
|
|
PROFILE_SHINE_UNKNOWN,
|
|
loadProfileSnapshot,
|
|
saveProfileGender,
|
|
saveProfileParamBlock,
|
|
saveProfileStatus,
|
|
} from '../services/user-profile-params.js';
|
|
import { buildIdentityLines } from '../services/user-connections.js';
|
|
import { openAvatarWizard } from '../components/avatar-wizard.js';
|
|
import { renderUserAvatar } from '../components/avatar-image.js';
|
|
|
|
export const pageMeta = { id: 'profile-edit-view', get title() { return t('screens.profile_edit_view.text_001'); } };
|
|
|
|
function accountRoleLabel(value) {
|
|
return value === PROFILE_ACCOUNT_ROLE_PRIMARY ? t('screens.profile_edit_view.text_009') : t('screens.profile_edit_view.text_010');
|
|
}
|
|
|
|
function shineStatusLabel(value) {
|
|
return value === PROFILE_SHINE_SHINING ? t('screens.profile_edit_view.text_011') : t('screens.profile_edit_view.text_012');
|
|
}
|
|
|
|
|
|
|
|
function officialSteps(firstName, lastName) {
|
|
const name = `${firstName} ${lastName}`.trim();
|
|
return [
|
|
{ title: t('dialogs.final.consent.official_steps.odin_chelovek_odin_ofitsialnyy_akkaunt'), text: t('dialogs.final.consent.official_steps.ofitsialnyy_akkaunt_vashe_zayavlenie_chto_eto_vash') },
|
|
{ title: t('dialogs.final.consent.official_steps.priznanie_zavisit_ot_drugih_lyudey'), text: t('dialogs.final.consent.official_steps.samo_zayavlenie_ne_delaet_lichnost_proverennoy_dru') },
|
|
{ title: t('dialogs.final.consent.official_steps.istoriya_perezhivaet_akkaunt'), text: t('dialogs.final.consent.official_steps.esli_vy_poteryaete_dostup_mozhno_zaregistrirovat_n') },
|
|
{ title: t('dialogs.final.consent.official_steps.eto_deystvitelno_vy'), text: t('dialogs.final.consent.official_steps.v_profile_ukazano_value1_podtverzhdayte_tolko_esli', { value1: name }), accept: t('dialogs.final.consent.official_steps.podtverzhdayu_chto_value1_moi_nastoyaschie_imya_i', { value1: name }) },
|
|
{ title: t('dialogs.final.consent.official_steps.podtverzhdaya_drugih_otvechayte_za_svoi_slova'), text: t('dialogs.final.consent.official_steps.ofitsialnyy_akkaunt_mozhet_podtverzhdat_osnovnye_a'), accept: t('dialogs.final.consent.official_steps.ponimayu_otvetstvennost_za_svoi_podtverzhdeniya') },
|
|
{ title: t('dialogs.final.consent.official_steps.publichnaya_zapis'), text: t('dialogs.final.consent.official_steps.zayavlenie_i_buduschie_podtverzhdeniya_popadayut_v'), accept: t('dialogs.final.consent.official_steps.ya_ponimayu_publichnost_i_dolgovremennoe_hranenie'), button: t('dialogs.final.consent.official_steps.stat_ofitsialnym') },
|
|
];
|
|
}
|
|
|
|
function shiningSteps() { return [
|
|
{ title: t('dialogs.final.consent.shining_steps.siyayuschiy_ofitsialnyy'), text: t('dialogs.final.consent.shining_steps.otmetit_sebya_siyayuschim_mozhno_i_s_neofitsialnog') },
|
|
{ title: t('dialogs.final.consent.shining_steps.chto_znachit_siyayuschiy'), text: t('dialogs.final.consent.shining_steps.v_shine_eto_chelovek_kotoryy_zanimaetsya_vnutrenni') },
|
|
{ title: t('dialogs.final.consent.shining_steps.1_chestnost'), text: t('dialogs.final.consent.shining_steps.siyayuschiy_staraetsya_ne_lgat_i_ne_vvodit_lyudey'), accept: t('dialogs.final.consent.shining_steps.chestnost_moy_printsip') },
|
|
{ title: t('dialogs.final.consent.shining_steps.2_duhovnoe_izmerenie'), text: t('dialogs.final.consent.shining_steps.vy_dopuskaete_chto_chelovek_ne_tolko_fizicheskoe_t'), accept: t('dialogs.final.consent.shining_steps.mne_blizko_takoe_ponimanie_cheloveka') },
|
|
{ title: t('dialogs.final.consent.shining_steps.3_razvitie'), text: t('dialogs.final.consent.shining_steps.siyayuschiy_stremitsya_uchitsya_osoznavat_sebya_i'), accept: t('dialogs.final.consent.shining_steps.ya_stremlyus_razvivatsya_i_delitsya_poleznym') },
|
|
{ title: t('dialogs.final.consent.shining_steps.4_zabota_o_mire'), text: t('dialogs.final.consent.shining_steps.siyayuschiy_staraetsya_delat_mir_vokrug_luchshe_sl'), accept: t('dialogs.final.consent.shining_steps.ya_hochu_prinosit_polzu_lyudyam_i_miru') },
|
|
{ title: t('dialogs.final.consent.shining_steps.5_svyazi_s_drugimi_siyayuschimi'), text: t('dialogs.final.consent.shining_steps.vzaimnye_znakomstva_i_podtverzhdeniya_drugih_lyude'), accept: t('dialogs.final.consent.shining_steps.ponimayu_chto_set_otsenivaet_ne_tolko_moyu_galochk') },
|
|
{ title: t('dialogs.final.consent.shining_steps.podtverzhdeniya_drugih'), text: t('dialogs.final.consent.shining_steps.tolko_ofitsialnyy_siyayuschiy_mozhet_podtverzhdat'), accept: t('dialogs.final.consent.shining_steps.budu_podtverzhdat_drugih_dobrosovestno') },
|
|
{ title: t('dialogs.final.consent.shining_steps.otkrytoe_zayavlenie'), text: t('dialogs.final.consent.shining_steps.otmetka_siyayuschiy_sozdayot_publichnuyu_zapis_eyo'), accept: t('dialogs.final.consent.shining_steps.ya_ponimayu_posledstviya_i_soglasen_na_opublikovat'), button: t('dialogs.final.consent.shining_steps.ya_siyayuschiy') },
|
|
]; }
|
|
|
|
// Ошибка – понятным сообщением внизу экрана, а не окном со стеком вызовов
|
|
// (подробности остаются в журнале приложения).
|
|
function showLocalErrorAlert(prefix, error) {
|
|
showToast(`${prefix}. ${toUserMessage(error, t('screens.profile_edit_view.text_006'))}`, { kind: 'error' });
|
|
}
|
|
|
|
function genderLabel(value) {
|
|
if (value === PROFILE_GENDER_MALE) return t('screens.profile_edit_view.text_013');
|
|
if (value === PROFILE_GENDER_FEMALE) return t('screens.profile_edit_view.text_014');
|
|
return t('screens.profile_edit_view.text_015');
|
|
}
|
|
|
|
const GENDER_OPTIONS = Object.freeze([
|
|
{ value: PROFILE_GENDER_MALE, get label() { return t('screens.profile_edit_view.text_002'); } },
|
|
{ value: PROFILE_GENDER_FEMALE, get label() { return t('screens.profile_edit_view.text_003'); } },
|
|
{ value: PROFILE_GENDER_UNKNOWN, get label() { return t('screens.profile_edit_view.text_004'); } },
|
|
]);
|
|
|
|
function escapeHtml(text) {
|
|
return String(text || '')
|
|
.replaceAll('&', '&')
|
|
.replaceAll('<', '<')
|
|
.replaceAll('>', '>')
|
|
.replaceAll('"', '"')
|
|
.replaceAll("'", ''');
|
|
}
|
|
|
|
export function render({ navigate, chrome }) {
|
|
const login = state.session.login || profile.login;
|
|
|
|
const screen = document.createElement('section');
|
|
screen.className = 'stack profile-screen';
|
|
|
|
chrome?.setTopbar(
|
|
createTopBar({
|
|
title: t('screens.profile_edit_view.text_005'),
|
|
back: { label: '←', onClick: () => navigate('profile-view') },
|
|
}),
|
|
);
|
|
|
|
const card = document.createElement('div');
|
|
card.className = 'stack profile-edit-card';
|
|
|
|
const topRow = document.createElement('div');
|
|
topRow.className = 'row';
|
|
topRow.innerHTML = `
|
|
<div class="row" style="gap:12px; align-items:center;">
|
|
<div class="profile-avatar-block" data-change-avatar="true" style="cursor:pointer;">
|
|
<div data-profile-avatar-slot="true"></div>
|
|
</div>
|
|
<div class="profile-identity-lines" data-profile-identity="true">
|
|
<div class="profile-identity-line profile-identity-login">${String(login || '').trim() || 'unknown'}</div>
|
|
</div>
|
|
</div>
|
|
<button class="secondary-btn profile-edit-reload" type="button" data-reload="true" hidden>${th('screens.profile_edit_view.text_028')}</button>
|
|
`;
|
|
|
|
const badgesRow = document.createElement('div');
|
|
badgesRow.className = 'chip-row profile-edit-statuses';
|
|
badgesRow.innerHTML = `
|
|
<button class="chip profile-toggle-btn is-no" type="button" data-status="account_role">${th('screens.profile_edit_view.text_029')}</button>
|
|
<button class="chip profile-toggle-btn is-no" type="button" data-status="shine">${th('screens.profile_edit_view.text_030')}</button>
|
|
`;
|
|
|
|
const status = document.createElement('div');
|
|
status.className = 'status-line';
|
|
status.textContent = t('dialogs.modals.profile_edit_view.label_003');
|
|
|
|
const listWrap = document.createElement('div');
|
|
listWrap.className = 'nav-list profile-param-list';
|
|
|
|
const reloadBtn = topRow.querySelector('[data-reload="true"]');
|
|
const accountRoleBtn = badgesRow.querySelector('[data-status="account_role"]');
|
|
const shineBtn = badgesRow.querySelector('[data-status="shine"]');
|
|
const avatarActionEl = topRow.querySelector('[data-change-avatar="true"]');
|
|
|
|
let currentFields = [];
|
|
let currentAccountRole = '';
|
|
let currentShineStatus = '';
|
|
let currentGender = PROFILE_GENDER_UNKNOWN;
|
|
let statusFlowOpen = false;
|
|
let currentAvatar = { value: '', source: '', txId: '', sha256Hex: '', timeMs: 0 };
|
|
const identityEl = topRow.querySelector('[data-profile-identity="true"]');
|
|
const avatarSlotEl = topRow.querySelector('[data-profile-avatar-slot="true"]');
|
|
|
|
function openGenderPickerModal(initialGender) {
|
|
const root = document.getElementById('modal-root');
|
|
if (!root) return Promise.resolve(null);
|
|
root.innerHTML = '';
|
|
|
|
const selected = GENDER_OPTIONS.some((item) => item.value === initialGender)
|
|
? initialGender
|
|
: PROFILE_GENDER_UNKNOWN;
|
|
|
|
root.innerHTML = `
|
|
<div class="modal" id="profile-gender-modal">
|
|
<div class="modal-card stack">
|
|
<h3 class="modal-title">${t('dialogs.modals.profile_edit_view.label_001')}</h3>
|
|
<p class="meta-muted">${t('dialogs.modals.profile_edit_view.label_002')}</p>
|
|
<select class="input profile-gender-select" id="profile-gender-select">
|
|
${GENDER_OPTIONS.map((item) => (
|
|
`<option value="${item.value}" ${item.value === selected ? 'selected' : ''}>${item.label}</option>`
|
|
)).join('')}
|
|
</select>
|
|
<div class="form-actions-grid">
|
|
<button class="secondary-btn" id="profile-gender-cancel" type="button">${t('dialogs.remaining.pages.profile_edit_view.markup.otmena')}</button>
|
|
<button class="primary-btn" id="profile-gender-save" type="button">${t('dialogs.remaining.pages.profile_edit_view.markup.sohranit')}</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
return new Promise((resolve) => {
|
|
const modal = root.querySelector('#profile-gender-modal');
|
|
const selectEl = root.querySelector('#profile-gender-select');
|
|
const saveEl = root.querySelector('#profile-gender-save');
|
|
const cancelEl = root.querySelector('#profile-gender-cancel');
|
|
if (!(modal instanceof HTMLElement) || !(selectEl instanceof HTMLSelectElement)) {
|
|
root.innerHTML = '';
|
|
resolve(null);
|
|
return;
|
|
}
|
|
|
|
const close = (value = null) => {
|
|
root.innerHTML = '';
|
|
resolve(value);
|
|
};
|
|
|
|
modal.addEventListener('click', (event) => {
|
|
if (event.target === modal) close(null);
|
|
});
|
|
cancelEl?.addEventListener('click', () => close(null));
|
|
saveEl?.addEventListener('click', () => close(selectEl.value || PROFILE_GENDER_UNKNOWN));
|
|
window.setTimeout(() => selectEl.focus(), 0);
|
|
});
|
|
}
|
|
|
|
function syncIdentity() {
|
|
if (!identityEl) return;
|
|
const firstName = currentFields.find((field) => field.key === 'first_name')?.value || '';
|
|
const lastName = currentFields.find((field) => field.key === 'last_name')?.value || '';
|
|
const lines = buildIdentityLines({ login, firstName, lastName });
|
|
identityEl.innerHTML = lines.map((line, idx) => (
|
|
`<div class="profile-identity-line${idx === lines.length - 1 ? ' profile-identity-login' : ''}">${escapeHtml(line)}</div>`
|
|
)).join('');
|
|
}
|
|
|
|
function updateAvatarUi() {
|
|
if (!(avatarSlotEl instanceof HTMLElement)) return;
|
|
const firstName = String(currentFields.find((field) => field.key === 'first_name')?.value || '').trim();
|
|
const lastName = String(currentFields.find((field) => field.key === 'last_name')?.value || '').trim();
|
|
avatarSlotEl.innerHTML = '';
|
|
avatarSlotEl.classList.toggle('is-shining', currentShineStatus === PROFILE_SHINE_SHINING);
|
|
avatarSlotEl.append(renderUserAvatar({
|
|
login,
|
|
firstName,
|
|
lastName,
|
|
avatar: (currentAvatar?.txId || currentAvatar?.sha256Hex)
|
|
? { ar: String(currentAvatar.txId || currentAvatar.ar || '').trim(), sha256Hex: String(currentAvatar?.sha256Hex || '').trim().toLowerCase() }
|
|
: null,
|
|
size: 'xl',
|
|
// Как в карточке профиля: без стеклянного кольца, которое вылезало за край экрана.
|
|
className: 'profile-avatar avatar-plain',
|
|
official: currentAccountRole === PROFILE_ACCOUNT_ROLE_PRIMARY,
|
|
}));
|
|
}
|
|
|
|
function updateStatusesUi() {
|
|
if (accountRoleBtn) {
|
|
accountRoleBtn.textContent = t('screens.profile_edit_view.text_020', { value1: accountRoleLabel(currentAccountRole) });
|
|
accountRoleBtn.classList.remove('is-no', 'is-yes-official', 'is-yes-shine', 'is-not-interested');
|
|
accountRoleBtn.classList.add(currentAccountRole === PROFILE_ACCOUNT_ROLE_PRIMARY ? 'is-yes-official' : 'is-no');
|
|
}
|
|
if (shineBtn) {
|
|
shineBtn.textContent = t('screens.profile_edit_view.text_021', { value1: shineStatusLabel(currentShineStatus) });
|
|
shineBtn.classList.remove('is-no', 'is-yes-official', 'is-yes-shine', 'is-not-interested');
|
|
if (currentShineStatus === PROFILE_SHINE_SHINING) shineBtn.classList.add('is-yes-shine');
|
|
else shineBtn.classList.add('is-no');
|
|
}
|
|
}
|
|
|
|
function updateGenderUi() {
|
|
const genderValueEl = listWrap.querySelector('[data-gender-value]');
|
|
if (!genderValueEl) return;
|
|
genderValueEl.textContent = genderLabel(currentGender);
|
|
}
|
|
|
|
function openFieldEditModal({ label, value, placeholder = '', maxLength = 300, multiline = false, suggestions = null }) {
|
|
const root = document.getElementById('modal-root');
|
|
if (!root) return Promise.resolve(null);
|
|
root.innerHTML = `
|
|
<div class="modal" id="profile-field-edit-modal">
|
|
<div class="modal-card stack">
|
|
<h3 class="modal-title">${t('dialogs.modals.profile_edit_view.change_prefix')}${escapeHtml(label)}</h3>
|
|
${multiline ? `<textarea
|
|
id="profile-field-edit-input"
|
|
class="input"
|
|
maxlength="${Number(maxLength || 300)}"
|
|
rows="${Number(maxLength || 300) > 1000 ? 12 : 4}"
|
|
placeholder="${escapeHtml(placeholder || t('dialogs.remaining.pages.profile_edit_view.openfieldeditmodal.vvedite_value1', { value1: label.toLowerCase() }))}"
|
|
>${escapeHtml(String(value || ''))}</textarea>` : `<input
|
|
id="profile-field-edit-input"
|
|
class="input"
|
|
type="text"
|
|
maxlength="${Number(maxLength || 300)}"
|
|
placeholder="${escapeHtml(placeholder || t('dialogs.remaining.pages.profile_edit_view.openfieldeditmodal.vvedite_value1', { value1: label.toLowerCase() }))}"
|
|
value="${escapeHtml(String(value || ''))}"
|
|
${suggestions?.length ? 'list="profile-field-edit-suggestions" autocomplete="off"' : ''}
|
|
/>${suggestions?.length ? `<datalist id="profile-field-edit-suggestions">${suggestions.map((item) => `<option value="${escapeHtml(item)}"></option>`).join('')}</datalist>` : ''}`}
|
|
<div class="meta-muted">${t('dialogs.final.profile.char_limit', { count: Number(maxLength || 300) })}</div>
|
|
<div class="form-actions-grid">
|
|
<button class="secondary-btn" id="profile-field-edit-cancel" type="button">${t('dialogs.remaining.pages.profile_edit_view.markup.otmena')}</button>
|
|
<button class="primary-btn" id="profile-field-edit-save" type="button">${t('dialogs.remaining.pages.profile_edit_view.markup.sohranit')}</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
return new Promise((resolve) => {
|
|
const modal = root.querySelector('#profile-field-edit-modal');
|
|
const inputEl = root.querySelector('#profile-field-edit-input');
|
|
const saveEl = root.querySelector('#profile-field-edit-save');
|
|
const cancelEl = root.querySelector('#profile-field-edit-cancel');
|
|
if (!(modal instanceof HTMLElement) || (!(inputEl instanceof HTMLInputElement) && !(inputEl instanceof HTMLTextAreaElement))) {
|
|
root.innerHTML = '';
|
|
resolve(null);
|
|
return;
|
|
}
|
|
|
|
const close = (nextValue = null) => {
|
|
root.innerHTML = '';
|
|
resolve(nextValue);
|
|
};
|
|
|
|
modal.addEventListener('click', (event) => {
|
|
if (event.target === modal) close(null);
|
|
});
|
|
cancelEl?.addEventListener('click', () => close(null));
|
|
saveEl?.addEventListener('click', () => close(inputEl.value));
|
|
inputEl.addEventListener('keydown', (event) => {
|
|
if (!multiline && event.key === 'Enter') {
|
|
event.preventDefault();
|
|
close(inputEl.value);
|
|
}
|
|
});
|
|
window.setTimeout(() => {
|
|
inputEl.focus();
|
|
inputEl.selectionStart = inputEl.value.length;
|
|
inputEl.selectionEnd = inputEl.value.length;
|
|
}, 0);
|
|
});
|
|
}
|
|
|
|
function renderFields(fields) {
|
|
listWrap.innerHTML = '';
|
|
fields.forEach((field) => {
|
|
const row = document.createElement('button');
|
|
row.type = 'button';
|
|
row.className = 'nav-row profile-param-item';
|
|
row.dataset.editField = field.key;
|
|
const value = String(field.value || '').trim();
|
|
row.innerHTML = `<span class="nav-row__hint">${escapeHtml(field.label)}</span><span class="nav-row__label${value ? '' : ' is-empty'}">${escapeHtml(value || t('screens.profile_edit_view.text_019'))}</span>`;
|
|
listWrap.append(row);
|
|
|
|
if (field.key === 'last_name') {
|
|
const genderRow = document.createElement('button');
|
|
genderRow.type = 'button';
|
|
genderRow.className = 'nav-row profile-param-item';
|
|
genderRow.dataset.editGender = 'true';
|
|
const genderText = genderLabel(currentGender);
|
|
const genderEmpty = currentGender !== PROFILE_GENDER_MALE && currentGender !== PROFILE_GENDER_FEMALE;
|
|
genderRow.innerHTML = `<span class="nav-row__hint">${th('screens.profile_edit_view.text_031')}</span><span class="nav-row__label${genderEmpty ? ' is-empty' : ''}" data-gender-value>${escapeHtml(genderEmpty ? t('screens.profile_edit_view.text_016') : genderText)}</span>`;
|
|
listWrap.append(genderRow);
|
|
}
|
|
});
|
|
}
|
|
|
|
async function refreshProfileSnapshot() {
|
|
status.className = 'status-line';
|
|
status.textContent = t('dialogs.modals.profile_edit_view.label_003');
|
|
reloadBtn.disabled = true;
|
|
accountRoleBtn.disabled = true;
|
|
shineBtn.disabled = true;
|
|
|
|
try {
|
|
const snapshot = await loadProfileSnapshot(login);
|
|
currentFields = snapshot.fields;
|
|
currentAccountRole = snapshot.accountRole || '';
|
|
currentShineStatus = snapshot.shineStatus || '';
|
|
currentGender = snapshot.gender || PROFILE_GENDER_UNKNOWN;
|
|
currentAvatar = snapshot.avatar || { value: '', source: '', txId: '', sha256Hex: '', timeMs: 0 };
|
|
|
|
syncIdentity();
|
|
renderFields(currentFields);
|
|
updateStatusesUi();
|
|
updateGenderUi();
|
|
updateAvatarUi();
|
|
|
|
status.className = 'status-line';
|
|
status.textContent = '';
|
|
} catch (error) {
|
|
status.className = 'status-line is-unavailable';
|
|
status.textContent = actionErrorText(t('dialogs.modals.profile_edit_view.label_004'), error);
|
|
showLocalErrorAlert(t('screens.profile_edit_view.text_007'), error);
|
|
} finally {
|
|
reloadBtn.disabled = false;
|
|
accountRoleBtn.disabled = false;
|
|
shineBtn.disabled = false;
|
|
}
|
|
}
|
|
|
|
async function onChangeAvatarClick() {
|
|
const accepted = await confirmPublicHistoryAction({
|
|
title: t('dialogs.final.consent.avatar_history_title'),
|
|
text: t('dialogs.final.consent.avatar_history_warning'),
|
|
confirmLabel: t('dialogs.final.consent.choose_avatar'),
|
|
});
|
|
if (!accepted || !screen.isConnected) return;
|
|
status.className = 'status-line';
|
|
status.textContent = t('dialogs.modals.profile_edit_view.label_005');
|
|
|
|
try {
|
|
await openAvatarWizard({
|
|
login,
|
|
storagePwd: state.session.storagePwdInMemory,
|
|
gateway: state.entrySettings.arweaveServer,
|
|
navigate,
|
|
onStatus: (message) => {
|
|
status.className = 'status-line';
|
|
status.textContent = String(message || '');
|
|
},
|
|
onAvatarSaved: async () => {
|
|
status.className = 'status-line';
|
|
status.textContent = t('dialogs.modals.profile_edit_view.label_006');
|
|
await refreshProfileSnapshot();
|
|
status.className = 'status-line is-available';
|
|
status.textContent = t('dialogs.modals.profile_edit_view.label_007');
|
|
},
|
|
});
|
|
if (!status.textContent) {
|
|
status.className = 'status-line';
|
|
}
|
|
} catch (error) {
|
|
status.className = 'status-line is-unavailable';
|
|
status.textContent = actionErrorText(t('dialogs.modals.profile_edit_view.label_008'), error);
|
|
}
|
|
}
|
|
|
|
async function onStatusClick(statusKey) {
|
|
if (statusFlowOpen) return;
|
|
statusFlowOpen = true;
|
|
try {
|
|
const isAccountRole = statusKey === 'account_role';
|
|
const alreadyOn = isAccountRole
|
|
? currentAccountRole === PROFILE_ACCOUNT_ROLE_PRIMARY
|
|
: currentShineStatus === PROFILE_SHINE_SHINING;
|
|
let accepted = false;
|
|
if (alreadyOn) {
|
|
accepted = await confirmDialog({
|
|
title: isAccountRole ? t('dialogs.final.consent.remove_official') : t('dialogs.final.consent.remove_shining'),
|
|
text: t('dialogs.pages.profile_edit_view.text_001'),
|
|
confirmLabel: t('dialogs.pages.profile_edit_view.confirmLabel_002'),
|
|
});
|
|
} else if (isAccountRole) {
|
|
const firstName = String(currentFields.find((field) => field.key === 'first_name')?.value || '').trim();
|
|
const lastName = String(currentFields.find((field) => field.key === 'last_name')?.value || '').trim();
|
|
if (!firstName || !lastName) {
|
|
await confirmDialog({
|
|
title: t('dialogs.pages.profile_edit_view.title_003'),
|
|
text: t('dialogs.pages.profile_edit_view.text_004'),
|
|
confirmLabel: t('dialogs.pages.profile_edit_view.confirmLabel_005'),
|
|
cancelLabel: t('dialogs.pages.profile_edit_view.cancelLabel_006'),
|
|
});
|
|
return;
|
|
}
|
|
accepted = await confirmConsentSteps({ title: t('dialogs.final.consent.official_title'), steps: officialSteps(firstName, lastName) });
|
|
} else {
|
|
accepted = await confirmConsentSteps({ title: t('dialogs.final.consent.shining_title'), steps: shiningSteps() });
|
|
}
|
|
if (!accepted || !screen.isConnected) return;
|
|
const nextValue = isAccountRole
|
|
? (alreadyOn ? PROFILE_ACCOUNT_ROLE_NON_VOTING : PROFILE_ACCOUNT_ROLE_PRIMARY)
|
|
: (alreadyOn ? PROFILE_SHINE_UNKNOWN : PROFILE_SHINE_SHINING);
|
|
status.className = 'status-line';
|
|
status.textContent = t('dialogs.modals.profile_edit_view.label_009');
|
|
accountRoleBtn.disabled = true;
|
|
shineBtn.disabled = true;
|
|
try {
|
|
await saveProfileStatus(login, statusKey, nextValue);
|
|
if (!screen.isConnected) return;
|
|
await refreshProfileSnapshot();
|
|
} catch (error) {
|
|
if (!screen.isConnected) return;
|
|
status.className = 'status-line is-unavailable';
|
|
const what = isAccountRole ? t('screens.profile_edit_view.text_017') : t('screens.profile_edit_view.text_018');
|
|
status.textContent = t('screens.profile_edit_view.text_022', { value1: what, value2: toUserMessage(error, t('dialogs.modals.profile_edit_view.label_010')) });
|
|
showLocalErrorAlert(t('screens.profile_edit_view.text_023', { value1: what }), error);
|
|
} finally {
|
|
if (screen.isConnected) {
|
|
accountRoleBtn.disabled = false;
|
|
shineBtn.disabled = false;
|
|
}
|
|
}
|
|
} finally {
|
|
statusFlowOpen = false;
|
|
}
|
|
}
|
|
|
|
async function onEditFieldClick(fieldKey) {
|
|
const field = currentFields.find((item) => item.key === fieldKey);
|
|
if (!field) return;
|
|
|
|
const entered = await openFieldEditModal({
|
|
label: field.label,
|
|
value: field.value || '',
|
|
placeholder: field.placeholder || '',
|
|
maxLength: field.maxLength || 300,
|
|
multiline: Boolean(field.multiline),
|
|
suggestions: field.suggestions,
|
|
});
|
|
if (entered === null) return;
|
|
if (String(entered).length > Number(field.maxLength || 300)) {
|
|
showToast(t('screens.profile_edit_view.text_024', { value1: field.label, value2: Number(field.maxLength || 300) }), { kind: 'info' });
|
|
return;
|
|
}
|
|
|
|
if (String(entered).trim() === String(field.value || '').trim()) return;
|
|
const accepted = await confirmPublicHistoryAction({
|
|
title: t('dialogs.final.consent.publish_change_title', { field: field.label }),
|
|
text: t('dialogs.final.consent.public_history_warning'),
|
|
confirmLabel: t('dialogs.final.consent.record_yes'),
|
|
cancelLabel: t('dialogs.final.consent.record_no'),
|
|
});
|
|
if (!accepted || !screen.isConnected) return;
|
|
|
|
status.className = 'status-line';
|
|
status.textContent = t('dialogs.modals.profile_edit_view.label_009');
|
|
|
|
try {
|
|
await saveProfileParamBlock(login, field.key, entered);
|
|
await refreshProfileSnapshot();
|
|
} catch (error) {
|
|
status.className = 'status-line is-unavailable';
|
|
status.textContent = t('screens.profile_edit_view.text_025', { value1: field.label, value2: toUserMessage(error, t('dialogs.modals.profile_edit_view.label_010')) });
|
|
showLocalErrorAlert(t('screens.profile_edit_view.text_026', { value1: field.label }), error);
|
|
}
|
|
}
|
|
|
|
async function onGenderClick() {
|
|
const nextGender = await openGenderPickerModal(currentGender);
|
|
if (!nextGender || nextGender === currentGender) return;
|
|
const accepted = await confirmPublicHistoryAction({
|
|
title: t('dialogs.final.consent.gender_publish_title'),
|
|
text: t('dialogs.final.consent.public_history_warning'),
|
|
confirmLabel: t('dialogs.final.consent.record_yes'),
|
|
cancelLabel: t('dialogs.final.consent.record_no'),
|
|
});
|
|
if (!accepted || !screen.isConnected) return;
|
|
|
|
status.className = 'status-line';
|
|
status.textContent = t('dialogs.modals.profile_edit_view.label_009');
|
|
|
|
try {
|
|
await saveProfileGender(login, nextGender);
|
|
await refreshProfileSnapshot();
|
|
} catch (error) {
|
|
status.className = 'status-line is-unavailable';
|
|
status.textContent = t('screens.profile_edit_view.text_027', { value1: toUserMessage(error, t('dialogs.modals.profile_edit_view.label_010')) });
|
|
showLocalErrorAlert(t('screens.profile_edit_view.text_008'), error);
|
|
}
|
|
}
|
|
|
|
listWrap.addEventListener('click', (event) => {
|
|
const target = event.target;
|
|
if (!(target instanceof HTMLElement)) return;
|
|
const genderRow = target.closest('[data-edit-gender="true"]');
|
|
if (genderRow) {
|
|
onGenderClick();
|
|
return;
|
|
}
|
|
const fieldRow = target.closest('[data-edit-field]');
|
|
const fieldKey = String(fieldRow?.getAttribute('data-edit-field') || '');
|
|
if (!fieldKey) return;
|
|
onEditFieldClick(fieldKey);
|
|
});
|
|
|
|
reloadBtn.addEventListener('click', refreshProfileSnapshot);
|
|
accountRoleBtn.addEventListener('click', () => onStatusClick('account_role'));
|
|
shineBtn.addEventListener('click', () => onStatusClick('shine'));
|
|
avatarActionEl?.addEventListener('click', () => { void onChangeAvatarClick(); });
|
|
|
|
card.append(topRow, badgesRow, status, listWrap);
|
|
screen.append(card);
|
|
|
|
updateAvatarUi();
|
|
refreshProfileSnapshot();
|
|
|
|
return screen;
|
|
}
|