SHA256
- styles/main.css: роли цветов (по умолчанию «Индиго»), шкала отступов/скруглений/шрифтов, цвета отношений для обеих тем; жёсткие цвета в стилях заменены на роли. - Палитра: пресеты и личные правки, «Оформление» Авто/День/Ночь, долгое нажатие — редактор цветов с экспортом/импортом. - Каналы: пузыри постов автора, плашки дней, строка «Написать в канал…», «О канале», создание канала с адресом из названия; лента открывается на свежих постах. - Чаты: плоский список, чипы-фильтры, пузыри, плашки дней; нижняя панель скрыта в переписке. - Корневые разделы — единая шапка; профиль и чужой профиль — общая карточка; настройки, кошелёк, сеансы — меню-списки. - Нижняя панель: иконки без подписей, бейджи на иконках. - confirmDialog вместо window.confirm/alert; на телефоне диалоги — шторки снизу. - docs/UI-Design/ISSUES-for-dev.md — найденные ошибки сервера/UI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
241 lines
8.5 KiB
JavaScript
241 lines
8.5 KiB
JavaScript
import { createTopBar } from '../components/topbar.js';
|
|
import { SHINE_CONNECTIONS_LOGO_SRC } from '../components/shine-logo.js';
|
|
import { renderUserAvatar } from '../components/avatar-image.js';
|
|
import { authService, state } from '../state.js';
|
|
import { loadRelationsForPair, loadUserProfileCard } from '../services/user-connections.js';
|
|
import { makeProfileLinksRoute } from '../services/shine-routes.js';
|
|
import { navigateBack } from '../router.js';
|
|
import { profileCardHtml, profileTileHtml } from '../components/profile-card.js';
|
|
|
|
export const pageMeta = { id: 'user', title: 'Профиль' };
|
|
|
|
function escapeHtml(text) {
|
|
return String(text || '')
|
|
.replaceAll('&', '&')
|
|
.replaceAll('<', '<')
|
|
.replaceAll('>', '>')
|
|
.replaceAll('"', '"')
|
|
.replaceAll("'", ''');
|
|
}
|
|
|
|
function effectiveSocial(flags = {}) {
|
|
if (flags.outCloseFriend) return 'close_friend';
|
|
if (flags.outFriend) return 'friend';
|
|
if (flags.outContact) return 'contact';
|
|
return 'none';
|
|
}
|
|
|
|
function relationMenuHtml(flags = {}) {
|
|
const current = effectiveSocial(flags);
|
|
const rows = [
|
|
['friend', 'Друг'],
|
|
['close_friend', 'Близкий друг'],
|
|
['contact', 'Контакт'],
|
|
];
|
|
return rows.map(([kind, label]) => `
|
|
<button type="button" class="user-profile-add-option${current === kind ? ' is-current' : ''}" data-relation-kind="${kind}">
|
|
<span>${escapeHtml(label)}</span>
|
|
<span class="user-profile-add-option-check" aria-hidden="true">${current === kind ? '✓' : ''}</span>
|
|
</button>`).join('');
|
|
}
|
|
|
|
export function render({ navigate, route, chrome }) {
|
|
const requestedLogin = String(route?.params?.login || '').trim();
|
|
const selfLogin = String(state.session.login || '').trim();
|
|
const screen = document.createElement('section');
|
|
screen.className = 'stack user-profile-screen';
|
|
|
|
const header = createTopBar({
|
|
title: 'Профиль',
|
|
back: { label: '←', onClick: () => navigateBack() },
|
|
});
|
|
header.classList.add('user-profile-header');
|
|
chrome?.setTopbar(header);
|
|
|
|
const status = document.createElement('div');
|
|
status.className = 'status-line user-profile-status';
|
|
status.textContent = 'Загрузка профиля...';
|
|
|
|
const body = document.createElement('div');
|
|
body.className = 'user-profile-body';
|
|
screen.append(status, body);
|
|
|
|
let card = null;
|
|
let relationFlags = null;
|
|
let relationLoadPromise = null;
|
|
let addMenu = null;
|
|
let addActionButton = null;
|
|
|
|
function updateRelationUi() {
|
|
if (!addMenu) return;
|
|
addMenu.innerHTML = relationMenuHtml(relationFlags || {});
|
|
const social = effectiveSocial(relationFlags || {});
|
|
addActionButton?.classList.toggle('is-active', social !== 'none');
|
|
addActionButton?.setAttribute('aria-label', social === 'none' ? 'Добавить' : 'Изменить связь');
|
|
}
|
|
|
|
async function ensureRelationFlags() {
|
|
if (relationFlags) return relationFlags;
|
|
if (relationLoadPromise) return relationLoadPromise;
|
|
if (!selfLogin || !card?.login) return {};
|
|
relationLoadPromise = loadRelationsForPair({ currentLogin: selfLogin, targetLogin: card.login })
|
|
.then((flags) => {
|
|
relationFlags = flags || {};
|
|
updateRelationUi();
|
|
return relationFlags;
|
|
})
|
|
.finally(() => {
|
|
relationLoadPromise = null;
|
|
});
|
|
return relationLoadPromise;
|
|
}
|
|
|
|
async function setRelationKind(kind, enabled) {
|
|
await authService.setUserRelation({
|
|
login: selfLogin,
|
|
toLogin: card.login,
|
|
kind,
|
|
enabled,
|
|
storagePwd: state.session.storagePwdInMemory,
|
|
});
|
|
}
|
|
|
|
async function changeSocial(next) {
|
|
const flags = await ensureRelationFlags();
|
|
const current = effectiveSocial(flags);
|
|
if (current === next) return;
|
|
|
|
if (next === 'contact') {
|
|
if (flags.outCloseFriend) await setRelationKind('close_friend', false);
|
|
if (flags.outFriend) await setRelationKind('friend', false);
|
|
if (!flags.outContact) await setRelationKind('contact', true);
|
|
}
|
|
if (next === 'friend') {
|
|
if (flags.outCloseFriend) await setRelationKind('close_friend', false);
|
|
if (!flags.outFriend) await setRelationKind('friend', true);
|
|
}
|
|
if (next === 'close_friend' && !flags.outCloseFriend) {
|
|
await setRelationKind('close_friend', true);
|
|
}
|
|
|
|
relationFlags = await loadRelationsForPair({ currentLogin: selfLogin, targetLogin: card.login });
|
|
updateRelationUi();
|
|
}
|
|
|
|
function renderProfile() {
|
|
if (!card) return;
|
|
const isSelf = card.login.toLowerCase() === selfLogin.toLowerCase();
|
|
const official = card.accountRole === 'primary';
|
|
const shining = card.shineStatus === 'shining';
|
|
|
|
body.innerHTML = profileCardHtml({
|
|
card,
|
|
login: requestedLogin,
|
|
isSelf,
|
|
beforeTilesHtml: '<div class="user-profile-add-menu" hidden></div>',
|
|
tilesHtml: isSelf ? '' : [
|
|
profileTileHtml({ icon: 'user-plus', label: 'Добавить', attrs: 'data-profile-action="add" aria-haspopup="menu" aria-expanded="false"' }),
|
|
profileTileHtml({ label: 'Связи', attrs: 'data-profile-action="links"', iconMarkup: `<img class="pf-tile-mandala" src="${SHINE_CONNECTIONS_LOGO_SRC}" alt="" aria-hidden="true">` }),
|
|
profileTileHtml({ icon: 'message', label: 'Написать', attrs: 'data-profile-action="chat"' }),
|
|
].join(''),
|
|
});
|
|
|
|
const avatarSlot = body.querySelector('.user-profile-avatar-slot');
|
|
avatarSlot?.append(renderUserAvatar({
|
|
login: card.login,
|
|
firstName: card.firstName,
|
|
lastName: card.lastName,
|
|
avatar: card.avatar,
|
|
size: 'xl',
|
|
className: 'user-profile-hero-avatar',
|
|
glow: shining,
|
|
official,
|
|
}));
|
|
|
|
addMenu = body.querySelector('.user-profile-add-menu');
|
|
addActionButton = body.querySelector('[data-profile-action="add"]');
|
|
updateRelationUi();
|
|
status.textContent = '';
|
|
|
|
if (!isSelf && selfLogin) {
|
|
void ensureRelationFlags().catch(() => {});
|
|
}
|
|
}
|
|
|
|
body.addEventListener('click', async (event) => {
|
|
if (!card) return;
|
|
const listButton = event.target.closest('[data-profile-list]');
|
|
if (listButton) {
|
|
const kind = listButton.dataset.profileList;
|
|
if (kind) navigate(`SHiNE/${encodeURIComponent(card.login)}/list/${encodeURIComponent(kind)}`);
|
|
return;
|
|
}
|
|
|
|
const relationButton = event.target.closest('[data-relation-kind]');
|
|
if (relationButton) {
|
|
if (!selfLogin) {
|
|
status.className = 'status-line user-profile-status is-unavailable';
|
|
status.textContent = 'Для добавления пользователя необходимо войти.';
|
|
return;
|
|
}
|
|
const next = relationButton.dataset.relationKind;
|
|
try {
|
|
addMenu?.classList.add('is-busy');
|
|
await changeSocial(next);
|
|
if (addMenu) addMenu.hidden = true;
|
|
addActionButton?.setAttribute('aria-expanded', 'false');
|
|
status.className = 'status-line user-profile-status';
|
|
status.textContent = '';
|
|
} catch (error) {
|
|
status.className = 'status-line user-profile-status is-unavailable';
|
|
status.textContent = `Ошибка: ${error?.message || 'Не удалось изменить связь'}`;
|
|
} finally {
|
|
addMenu?.classList.remove('is-busy');
|
|
}
|
|
return;
|
|
}
|
|
|
|
const actionButton = event.target.closest('[data-profile-action]');
|
|
const action = actionButton?.dataset.profileAction;
|
|
if (action === 'add') {
|
|
if (!addMenu) return;
|
|
navigate(`SHiNE/${encodeURIComponent(card.login)}/manage`);
|
|
return;
|
|
}
|
|
if (action === 'links') {
|
|
navigate(makeProfileLinksRoute(card.login));
|
|
return;
|
|
}
|
|
if (action === 'chat') {
|
|
navigate(`chat/${encodeURIComponent(card.login)}`);
|
|
}
|
|
});
|
|
|
|
const handleOutsidePointer = (event) => {
|
|
if (!addMenu || addMenu.hidden) return;
|
|
if (event.target instanceof Node && body.contains(event.target)) {
|
|
const insideActions = event.target.closest?.('.user-profile-actions-wrap');
|
|
if (insideActions) return;
|
|
}
|
|
addMenu.hidden = true;
|
|
addActionButton?.setAttribute('aria-expanded', 'false');
|
|
};
|
|
document.addEventListener('pointerdown', handleOutsidePointer);
|
|
|
|
async function refresh() {
|
|
card = await loadUserProfileCard(requestedLogin);
|
|
renderProfile();
|
|
}
|
|
|
|
refresh().catch((error) => {
|
|
status.className = 'status-line user-profile-status is-unavailable';
|
|
status.textContent = `Ошибка: ${error?.message || 'unknown'}`;
|
|
});
|
|
|
|
screen.cleanup = () => {
|
|
document.removeEventListener('pointerdown', handleOutsidePointer);
|
|
};
|
|
|
|
return screen;
|
|
}
|