diff --git a/src/assets/scss/pages/_dashboard.scss b/src/assets/scss/pages/_dashboard.scss index 377374f..8840913 100644 --- a/src/assets/scss/pages/_dashboard.scss +++ b/src/assets/scss/pages/_dashboard.scss @@ -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; diff --git a/src/views/dashboard/helpers.js b/src/views/dashboard/helpers.js index f22804e..ce4e3fe 100644 --- a/src/views/dashboard/helpers.js +++ b/src/views/dashboard/helpers.js @@ -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) { diff --git a/src/views/dashboard/widgets/MilestoneTeamLeaderboard.jsx b/src/views/dashboard/widgets/MilestoneTeamLeaderboard.jsx index 38b3e67..7f8b6f0 100644 --- a/src/views/dashboard/widgets/MilestoneTeamLeaderboard.jsx +++ b/src/views/dashboard/widgets/MilestoneTeamLeaderboard.jsx @@ -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 ( +
+
+ {user && photo ? : (user?.initials || '-')} +
+
{user?.name || '-'}
+
{user ? user.score : '-'}
+
+ ); +} + +function Versus({ users }) { + const top = [...users] + .sort((a, b) => Number(a.rank) - Number(b.rank)) + .slice(0, 3); + if (!top.length) return

No data

; + return ( +
2 ? 'is-three' : ''}`}> + {top.map((user, index) => ( + + {index > 0 ? VS : null} + + + ))} +
+ ); +} + function RankList({ rows }) { if (!rows.length) return

No data

; 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 }) { ))} ) : null} - {isList ? ( + {mode === 'list' ? ( + ) : mode === 'versus' ? ( + ) : (
@@ -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); diff --git a/src/views/leaderboard/Dashboard.jsx b/src/views/leaderboard/Dashboard.jsx index b0ea863..0e699e4 100644 --- a/src/views/leaderboard/Dashboard.jsx +++ b/src/views/leaderboard/Dashboard.jsx @@ -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,