SHA256
Личные сообщения: - поиск по переписке с подсветкой, переход к дате по календарю; - экран «Медиа и файлы» (/chat/<login>/media); - «без звука» и закрепление чатов (на устройстве), push от заглушённых не показывается; - новая нижняя панель ввода, круглый спиннер истории, медиа-карусель; - история загружается в ~16 раз быстрее: ключ расшифровки достаётся один раз на страницу; - исправлены прозрачные окна подтверждения в чате. Связи: - карта переписана на canvas (graph-canvas.js вместо force-graph.js): плавная анимация без дёрганья, панорама, масштаб щипком/колесом/кнопками, перетаскивание людей; - ручная раскладка и режимы «По близости»/«По группам» запоминаются на устройстве; - цвет нити – тип связи, пунктир – связь с одной стороны, аура только у сияющих; - карточка человека: раскрыть связи на месте, в центр, профиль, написать, заметка; - «Недавние» заменены раскрытием связей; фильтр «Заметки». Личные заметки о людях (текст и цветная метка, только на устройстве) – на карте и в профиле.
146 lines
5.4 KiB
JavaScript
146 lines
5.4 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 { state } from '../state.js';
|
|
import { 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';
|
|
import { createPersonNotePreview, openPersonNoteSheet } from '../components/person-note-sheet.js';
|
|
import { iconHtml } from '../components/ui-icon.js';
|
|
import { PEOPLE_NOTES_EVENT, getPersonNote } from '../services/people-notes.js';
|
|
|
|
export const pageMeta = { id: 'user', title: 'Профиль' };
|
|
|
|
function escapeHtml(text) {
|
|
return String(text || '')
|
|
.replaceAll('&', '&')
|
|
.replaceAll('<', '<')
|
|
.replaceAll('>', '>')
|
|
.replaceAll('"', '"')
|
|
.replaceAll("'", ''');
|
|
}
|
|
|
|
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 disposed = false;
|
|
let noteSheet = null;
|
|
|
|
function openNote() {
|
|
noteSheet?.close();
|
|
const name = [card.firstName, card.lastName].map((v) => String(v || '').trim()).filter(Boolean).join(' ') || card.login;
|
|
noteSheet = openPersonNoteSheet({ login: card.login, name, onClose: () => { noteSheet = null; } });
|
|
}
|
|
|
|
function renderProfile() {
|
|
if (!card || disposed) return;
|
|
const isSelf = card.login.toLowerCase() === selfLogin.toLowerCase();
|
|
const note = isSelf ? null : getPersonNote(card.login);
|
|
|
|
body.innerHTML = profileCardHtml({
|
|
card,
|
|
login: requestedLogin,
|
|
isSelf,
|
|
tilesHtml: isSelf ? '' : [
|
|
profileTileHtml({ icon: 'user-plus', label: 'Добавить связь', attrs: 'data-profile-action="add"' }),
|
|
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(''),
|
|
});
|
|
|
|
// Личная заметка – сразу под кнопками действий; видна только владельцу аккаунта.
|
|
let noteEl = createPersonNotePreview(note, { className: 'user-profile-note', onClick: openNote });
|
|
if (noteEl) {
|
|
noteEl.setAttribute('aria-label', `Ваша заметка: ${noteEl.textContent}. Изменить`);
|
|
} else if (!isSelf) {
|
|
noteEl = document.createElement('button');
|
|
noteEl.type = 'button';
|
|
noteEl.className = 'text-btn user-profile-note-add';
|
|
noteEl.innerHTML = `${iconHtml('edit')}<span>Добавить личную заметку</span>`;
|
|
noteEl.addEventListener('click', openNote);
|
|
}
|
|
if (noteEl) body.querySelector('.pf-tiles-wrap')?.after(noteEl);
|
|
|
|
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',
|
|
official: card.accountRole === 'primary',
|
|
}));
|
|
|
|
status.textContent = '';
|
|
}
|
|
|
|
body.addEventListener('click', (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 actionButton = event.target.closest('[data-profile-action]');
|
|
const action = actionButton?.dataset.profileAction;
|
|
if (action === 'add') {
|
|
navigate(`SHiNE/${encodeURIComponent(card.login)}/manage`);
|
|
return;
|
|
}
|
|
if (action === 'links') {
|
|
navigate(makeProfileLinksRoute(card.login));
|
|
return;
|
|
}
|
|
if (action === 'chat') {
|
|
navigate(`chat/${encodeURIComponent(card.login)}`);
|
|
}
|
|
});
|
|
|
|
const onNotesChanged = () => renderProfile();
|
|
window.addEventListener(PEOPLE_NOTES_EVENT, onNotesChanged);
|
|
screen.cleanup = () => {
|
|
if (disposed) return;
|
|
disposed = true;
|
|
window.removeEventListener(PEOPLE_NOTES_EVENT, onNotesChanged);
|
|
noteSheet?.close();
|
|
};
|
|
|
|
async function refresh() {
|
|
const loaded = await loadUserProfileCard(requestedLogin);
|
|
if (disposed) return;
|
|
card = loaded;
|
|
renderProfile();
|
|
}
|
|
|
|
refresh().catch((error) => {
|
|
if (disposed) return;
|
|
status.className = 'status-line user-profile-status is-unavailable';
|
|
status.textContent = `Ошибка: ${error?.message || 'unknown'}`;
|
|
});
|
|
|
|
return screen;
|
|
}
|