SHA256
- Слева «Официальный», справа «Сияющий»: числа «подтвердили» и «подтвердил(а)» открывают списки. - У активного статуса числа его цветом; на своём профиле обе стороны видны всегда, пустая – бледнее. - Значки под именем и нижний раздел «Сияние» убраны – они повторяли эти числа.
134 lines
7.0 KiB
JavaScript
134 lines
7.0 KiB
JavaScript
// 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('<', '<')
|
||
.replaceAll('>', '>')
|
||
.replaceAll('"', '"')
|
||
.replaceAll("'", ''');
|
||
}
|
||
|
||
const esc = escapeProfileHtml;
|
||
|
||
// Карточка статуса у аватара: кто подтвердил этот аккаунт и кого подтвердил он сам.
|
||
function statusSideHtml({ kind, title, active, received, given, verb }) {
|
||
const isOfficial = kind === 'primary';
|
||
const receivedKind = isOfficial ? 'primary_received' : 'shine_received';
|
||
const givenKind = isOfficial ? 'primary_given' : 'shine_given';
|
||
return `
|
||
<section class="pf-sc pf-sc--${esc(kind)}${active ? ' is-active' : ' is-empty'}" aria-label="${esc(title)}">
|
||
<div class="pf-sc__title">${esc(title)}</div>
|
||
<button type="button" class="pf-sc__row" data-profile-list="${receivedKind}" aria-label="${esc(title)}: подтвердили ${Number(received || 0)}">
|
||
<strong>${Number(received || 0)}</strong><span>подтвердили</span>
|
||
</button>
|
||
<button type="button" class="pf-sc__row" data-profile-list="${givenKind}" aria-label="${esc(title)}: ${esc(verb)} ${Number(given || 0)}">
|
||
<strong>${Number(given || 0)}</strong><span>${esc(verb)}</span>
|
||
</button>
|
||
</section>`;
|
||
}
|
||
|
||
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 verb = card?.gender === 'female' ? 'подтвердила' : card?.gender === 'male' ? 'подтвердил' : 'подтвердил(а)';
|
||
const officialSide = (isSelf || official || primaryReceived || primaryGiven)
|
||
? statusSideHtml({ kind: 'primary', title: 'Официальный', active: official, received: primaryReceived, given: primaryGiven, verb })
|
||
: '';
|
||
const shineSide = (isSelf || shining || shineReceived || shineGiven)
|
||
? statusSideHtml({ kind: 'shine', title: 'Сияющий', active: shining, received: shineReceived, given: shineGiven, verb })
|
||
: '';
|
||
|
||
return `
|
||
<div class="pf-hero" aria-label="Профиль ${esc(cardLogin)}">
|
||
<div class="pf-identity">
|
||
<div class="pf-side pf-side--left">${officialSide}</div>
|
||
<div class="pf-avatar user-profile-avatar-slot${shining ? ' is-shining' : ''}"></div>
|
||
<div class="pf-side pf-side--right">${shineSide}</div>
|
||
</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>` : ''}
|
||
</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>` : ''}
|
||
|
||
${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>`;
|
||
}
|