Leaderboard changes
This commit is contained in:
parent
e4ddd2de13
commit
3d347e3e45
|
|
@ -201,6 +201,91 @@
|
|||
color: #4a4a4a;
|
||||
box-shadow: 0 12px 18px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
.mlb-versus {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
.mlb-versus-side {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
.mlb-versus-avatar-wrap {
|
||||
position: relative;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.mlb-versus-avatar {
|
||||
width: 88px;
|
||||
height: 88px;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 700;
|
||||
color: #4b4b4b;
|
||||
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
.mlb-versus-avatar img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
.mlb-versus-name {
|
||||
margin-top: 8px;
|
||||
max-width: 140px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
line-height: 1.25;
|
||||
color: #2b2b2b;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
.mlb-versus-score {
|
||||
margin-top: 10px;
|
||||
min-width: 64px;
|
||||
padding: 6px 16px;
|
||||
border-radius: 999px;
|
||||
background: #fff;
|
||||
font-weight: 700;
|
||||
color: #2b2b2b;
|
||||
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
.mlb-versus.is-three .mlb-versus-avatar {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
}
|
||||
.mlb-versus.is-three .mlb-versus-badge {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
margin-top: 18px;
|
||||
flex-basis: 36px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.mlb-versus-badge {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
margin-top: 22px;
|
||||
border-radius: 50%;
|
||||
background: #6d4aff;
|
||||
color: #fff;
|
||||
font-size: 13px;
|
||||
font-weight: 800;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 0 0 44px;
|
||||
box-shadow: 0 6px 14px rgba(109, 74, 255, 0.35);
|
||||
}
|
||||
.mlb-rank-list { margin-top: 14px; }
|
||||
.mlb-rank-row {
|
||||
display: flex;
|
||||
|
|
|
|||
|
|
@ -59,10 +59,8 @@ export function rankRoleName(rankRole) {
|
|||
return String(rankRole.name || '');
|
||||
}
|
||||
|
||||
export function rankRolePillLabel(title, limit, roleName) {
|
||||
const label = String(title || '').trim() || String(roleName || '').trim() || 'Role';
|
||||
if (/^\s*top\s+\d+/i.test(label)) return label;
|
||||
return `Top ${Number(limit) || 10} ${label}`;
|
||||
export function rankRolePillLabel(title, roleName) {
|
||||
return String(title || '').trim() || String(roleName || '').trim() || 'Role';
|
||||
}
|
||||
|
||||
export function asArray(value) {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,19 @@
|
|||
import { useEffect, useState } from 'react';
|
||||
import { Fragment, useEffect, useState } from 'react';
|
||||
import { Link } from 'react-router';
|
||||
import { Spinner } from 'react-bootstrap';
|
||||
import { signedGet, isSuccess } from '@/api/client';
|
||||
import { asArray, rankRoleId, rankRoleName, rankRolePillLabel, userInitials } from '@/views/dashboard/helpers';
|
||||
import EmptyChart from '@/views/dashboard/EmptyChart';
|
||||
|
||||
function isTeamView(board) {
|
||||
const flag = board?.team_view;
|
||||
return flag === true || flag === 1 || flag === '1' || flag === 'true';
|
||||
}
|
||||
|
||||
function sectionsFor(board) {
|
||||
const roleRanks = asArray(board?.role_ranks);
|
||||
if (roleRanks.length) return roleRanks;
|
||||
if (isTeamView(board)) return [];
|
||||
return asArray(board?.rank_roles);
|
||||
}
|
||||
|
||||
|
|
@ -18,13 +24,18 @@ function rankedRowsFromSection(section) {
|
|||
const highlightCount = Number(section?.highlight_count) > 0 ? Number(section.highlight_count) : 0;
|
||||
const color = /^#[0-9A-Fa-f]{6}$/.test(section?.highlight_color || '') ? section.highlight_color : '';
|
||||
return source.map((row, index) => {
|
||||
const info = row.user || row.team || {};
|
||||
const isTeam = Boolean(row.team) && !row.user;
|
||||
const info = isTeam ? row.team : (row.user || {});
|
||||
const name = String(info.name || '').trim();
|
||||
const raw = isTeam
|
||||
? String(info.icon || info.image || '').trim()
|
||||
: String(info.avatar || '').trim();
|
||||
const avatar = !isTeam && raw.includes('ui-avatars.com') ? '' : raw;
|
||||
return {
|
||||
rank: row.rank ?? index + 1,
|
||||
name,
|
||||
initials: userInitials(name),
|
||||
avatar: info.avatar || info.icon || '',
|
||||
avatar,
|
||||
score: Number.isFinite(Number(row.score)) ? Number(row.score) : 0,
|
||||
highlight: Boolean(color) && index < highlightCount,
|
||||
color,
|
||||
|
|
@ -79,6 +90,36 @@ function Podium({ users }) {
|
|||
);
|
||||
}
|
||||
|
||||
function VersusSide({ user }) {
|
||||
const photo = user?.avatar && !String(user.avatar).includes('ui-avatars.com');
|
||||
return (
|
||||
<div className={`mlb-versus-side ${user ? '' : 'is-empty'}`}>
|
||||
<div className="mlb-versus-avatar">
|
||||
{user && photo ? <img src={user.avatar} alt="" /> : (user?.initials || '-')}
|
||||
</div>
|
||||
<div className="mlb-versus-name" title={user?.name || ''}>{user?.name || '-'}</div>
|
||||
<div className="mlb-versus-score">{user ? user.score : '-'}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Versus({ users }) {
|
||||
const top = [...users]
|
||||
.sort((a, b) => Number(a.rank) - Number(b.rank))
|
||||
.slice(0, 3);
|
||||
if (!top.length) return <p className="text-muted mb-0 mt-2">No data</p>;
|
||||
return (
|
||||
<div className={`mlb-versus ${top.length > 2 ? 'is-three' : ''}`}>
|
||||
{top.map((user, index) => (
|
||||
<Fragment key={`${user.rank}-${user.name}`}>
|
||||
{index > 0 ? <span className="mlb-versus-badge">VS</span> : null}
|
||||
<VersusSide user={user} />
|
||||
</Fragment>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RankList({ rows }) {
|
||||
if (!rows.length) return <p className="text-muted mb-0 mt-2">No data</p>;
|
||||
return (
|
||||
|
|
@ -102,8 +143,8 @@ function LeaderboardCard({ item }) {
|
|||
const [activeIndex, setActiveIndex] = useState(0);
|
||||
const pills = item.pills || [];
|
||||
const active = pills[activeIndex] || pills[0];
|
||||
const rows = active?.rows || [];
|
||||
const isList = active?.view_mode === 'list';
|
||||
const rows = (active?.rows || item.rows || []).slice(0, 3);
|
||||
const mode = active?.view_mode || '';
|
||||
const detailsUrl = active?.url || item.details_url || '#';
|
||||
|
||||
return (
|
||||
|
|
@ -134,8 +175,10 @@ function LeaderboardCard({ item }) {
|
|||
))}
|
||||
</div>
|
||||
) : null}
|
||||
{isList ? (
|
||||
{mode === 'list' ? (
|
||||
<RankList rows={rows} />
|
||||
) : mode === 'versus' ? (
|
||||
<Versus users={rows} />
|
||||
) : (
|
||||
<div className="mlb-podium">
|
||||
<Podium users={rows.slice(0, 3)} />
|
||||
|
|
@ -160,14 +203,14 @@ export default function MilestoneTeamLeaderboard({ widget }) {
|
|||
}
|
||||
const mapped = leaderboards.map((board) => {
|
||||
const sections = sectionsFor(board);
|
||||
const oldTeam = isTeamView(board) && !asArray(board?.role_ranks).length;
|
||||
const pills = sections.map((section, index) => {
|
||||
const limit = Number(section.limit) > 0 ? Number(section.limit) : 10;
|
||||
const roleId = section.show_as === 'team' ? '' : rankRoleId(section);
|
||||
const params = new URLSearchParams({ id: board.id || '' });
|
||||
if (roleId) params.set('role', roleId);
|
||||
const label = section.show_as === 'team'
|
||||
? (String(section.title || '').trim() || 'Teams')
|
||||
: rankRolePillLabel(section.title, limit, rankRoleName(section));
|
||||
: rankRolePillLabel(section.title, rankRoleName(section));
|
||||
return {
|
||||
label,
|
||||
url: `/leaderboard/dashboard?${params.toString()}`,
|
||||
|
|
@ -184,6 +227,7 @@ export default function MilestoneTeamLeaderboard({ widget }) {
|
|||
interval_label: `${start}${start && end ? ' – ' : ''}${end}`.trim(),
|
||||
details_url: pills[0]?.url || `/leaderboard/dashboard?id=${encodeURIComponent(board.id || '')}`,
|
||||
pills,
|
||||
rows: oldTeam ? rankedRowsFromSection({ teams: asArray(board.rank_roles) }) : [],
|
||||
};
|
||||
});
|
||||
setItems(mapped);
|
||||
|
|
|
|||
|
|
@ -63,11 +63,10 @@ function buildPills(leaderboardId, selectedRoleId, rankRoles, groups, period) {
|
|||
roles = [...roles].sort((a, b) => Number(a?.sort_order || 0) - Number(b?.sort_order || 0));
|
||||
return roles.map((rankRole, index) => {
|
||||
const roleId = rankRoleId(rankRole);
|
||||
const limit = Number(rankRole?.limit) > 0 ? Number(rankRole.limit) : 10;
|
||||
const params = new URLSearchParams({ id: leaderboardId, role: roleId });
|
||||
if (period) params.set('period', period);
|
||||
return {
|
||||
label: rankRolePillLabel(rankRole?.title, limit, rankRoleName(rankRole)),
|
||||
label: rankRolePillLabel(rankRole?.title, rankRoleName(rankRole)),
|
||||
to: `/leaderboard/dashboard?${params.toString()}`,
|
||||
active: selectedRoleId ? roleId === selectedRoleId : index === 0,
|
||||
roleId,
|
||||
|
|
|
|||
Loading…
Reference in New Issue