Files
SHiNE-server/shine-UI/js/components/profile-card.js
T
q 694aaf1f0e Профиль: поле «Город»
Город – обычное поле профиля (параметр city, тот же блок профиля, что у имени и пола):
в редактировании – между полом и адресом, с подсказками городов при вводе; в шапке профиля –
под логином («📍 Москва»). Из него собирается раскладка «Города» на карте связей. Подсказка
у адреса теперь «Улица, дом» – город отдельно. Сервер и формат блокчейна не менялись.
2026-10-13 14:09:35 +03:00

161 lines
7.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// data-profile-list / data-self-profile-action / data-profile-action обрабатывают profile-view.js и user-profile-view.js.
import { iconHtml } from './ui-icon.js';
import { displayCity } from '../services/cities.js';
export function escapeProfileHtml(text) {
return String(text || '')
.replaceAll('&', '&')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('"', '&quot;')
.replaceAll("'", '&#39;');
}
const esc = escapeProfileHtml;
// Раздел статуса («Сияние», «Официальный»): кто подтвердил этот аккаунт и кого подтвердил он сам.
function statusSectionHtml({ kind, title, received, given, receivedLabel, givenLabel }) {
const receivedCount = Number(received || 0);
const givenCount = Number(given || 0);
const isOfficial = kind === 'primary';
return `
<section class="pf-status-section pf-status-section--${esc(kind)}" aria-label="${esc(title)}">
<h3 class="nav-list__title">${esc(title)}</h3>
<div class="nav-list">
<button type="button" class="nav-row" data-profile-list="${isOfficial ? 'primary_received' : 'shine_received'}">
<span class="nav-row__label">${esc(receivedLabel)}</span>
<span class="nav-row__hint">${esc(peopleCount(receivedCount))}</span>
</button>
<button type="button" class="nav-row" data-profile-list="${isOfficial ? 'primary_given' : 'shine_given'}">
<span class="nav-row__label">${esc(givenLabel)}</span>
<span class="nav-row__hint">${esc(peopleCount(givenCount))}</span>
</button>
</div>
</section>`;
}
function peopleCount(count) {
if (!count) return 'Пока никого';
const mod10 = count % 10;
const mod100 = count % 100;
const word = mod10 === 1 && mod100 !== 11 ? 'человек' : (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) ? 'человека' : 'человек';
return `${count} ${word}`;
}
function statHtml({ kind, label, valueHtml, ariaLabel }) {
return `
<button type="button" class="pf-stat" data-profile-list="${esc(kind)}" aria-label="${esc(ariaLabel)}">
<span class="pf-stat-value">${valueHtml}</span>
<span class="pf-stat-label">${esc(label)}</span>
</button>`;
}
function contactRows(card) {
return [
['Ссылки', card?.web],
['Телефон', card?.phone],
['Адрес', card?.address],
]
.filter(([, value]) => String(value || '').trim())
.map(([label, value]) => `
<div class="pf-row">
<span class="pf-row-label">${esc(label)}</span>
<span class="pf-row-value">${esc(value)}</span>
</div>`)
.join('');
}
/**
* @param {object} opts
* @param {object} opts.card карточка профиля (loadUserProfileCard)
* @param {string} opts.login логин на случай, если в карточке его нет
* @param {string} opts.tilesHtml плитки действий (свои/чужие)
* @param {string} [opts.tilesWrapClass] доп. класс обёртки плиток (для меню «Добавить»)
* @param {string} [opts.beforeTilesHtml] разметка внутри обёртки перед плитками
*/
export function profileCardHtml({ card, login = '', tilesHtml = '', tilesWrapClass = '', beforeTilesHtml = '', isSelf = true }) {
const stats = card?.stats || {};
const official = card?.accountRole === 'primary';
const shining = card?.shineStatus === 'shining';
const cardLogin = card?.login || login;
const city = displayCity(card?.city);
const fullName = [card?.firstName, card?.lastName].map((v) => String(v || '').trim()).filter(Boolean).join(' ');
const displayName = fullName || cardLogin || 'Профиль';
const about = String(card?.about || '').trim();
const spiritualPath = String(card?.spiritualPath || '').trim();
const contacts = contactRows(card);
const aboutRow = (about || isSelf) ? `
<div class="pf-row pf-row--block">
<span class="pf-row-label">О себе</span>
<p class="pf-row-text${about ? '' : ' is-empty'}">${esc(about || 'Не заполнено')}</p>
</div>` : '';
const pathRow = spiritualPath ? `
<div class="pf-row pf-row--block">
<span class="pf-row-label">Духовный путь</span>
<p class="pf-row-text">${esc(spiritualPath)}</p>
</div>` : '';
const listInner = aboutRow + contacts + pathRow;
const listHtml = listInner.trim() ? `<div class="pf-list">${listInner}</div>` : '';
const friends = Number(stats.friendsCount || 0);
const closeFriends = Number(stats.closeFriendsCount || 0);
const shineReceived = Number(stats.shineReceivedCount || 0);
const shineGiven = Number(stats.shineGivenCount || 0);
const primaryReceived = Number(stats.primaryReceivedCount || 0);
const primaryGiven = Number(stats.primaryGivenCount || 0);
// Раздел виден у сияющих и у всех, кого уже подтверждали или кто подтверждал сам.
const shineSection = (shining || shineReceived || shineGiven)
? statusSectionHtml({
kind: 'shine',
title: 'Сияние',
received: shineReceived,
given: shineGiven,
receivedLabel: 'Подтвердили, что сияющий',
givenLabel: 'Подтвердил сияющими',
})
: '';
const officialSection = (official || primaryReceived || primaryGiven)
? statusSectionHtml({
kind: 'primary',
title: 'Официальный аккаунт',
received: primaryReceived,
given: primaryGiven,
receivedLabel: 'Подтвердили, что официальный',
givenLabel: 'Подтвердил официальными',
})
: '';
const badges = [
shining ? '<span class="pf-badge pf-badge--shine">Сияющий</span>' : '',
official ? '<span class="pf-badge pf-badge--official">Официальный</span>' : '',
].join('');
return `
<div class="pf-hero" aria-label="Профиль ${esc(cardLogin)}">
<div class="pf-avatar user-profile-avatar-slot${shining ? ' is-shining' : ''}"></div>
<h2 class="pf-name">${esc(displayName)}</h2>
<div class="pf-login">@${esc(cardLogin)}</div>
${city ? `<div class="pf-city">${iconHtml('place')}<span>${esc(city)}</span></div>` : ''}
${badges ? `<div class="pf-badges">${badges}</div>` : ''}
</div>
<div class="pf-stats">
${statHtml({ kind: 'friends', label: 'Друзья', valueHtml: closeFriends ? `${friends}<small> · ${closeFriends} близк.</small>` : String(friends), ariaLabel: `Друзья: ${friends}, близкие: ${closeFriends}` })}
${statHtml({ kind: 'channels_owned', label: 'Каналы', valueHtml: String(Number(stats.ownedPublicChannelsCount || 0)), ariaLabel: `Каналы: ${Number(stats.ownedPublicChannelsCount || 0)}` })}
${statHtml({ kind: 'channels_following', label: 'Подписки', valueHtml: String(Number(stats.followingChannelsCount || 0)), ariaLabel: `Подписки: ${Number(stats.followingChannelsCount || 0)}` })}
</div>
${tilesHtml ? `
<div class="pf-tiles-wrap user-profile-actions-wrap ${esc(tilesWrapClass)}">
${beforeTilesHtml}
<div class="pf-tiles user-profile-actions">${tilesHtml}</div>
</div>` : ''}
${shineSection}
${officialSection}
${listHtml}`;
}
export function profileTileHtml({ icon, label, attrs = '', iconMarkup = '' }) {
return `<button type="button" class="pf-tile user-profile-action-btn" ${attrs}>${iconMarkup || iconHtml(icon)}<span>${esc(label)}</span></button>`;
}