// Ranking โ€” school / global / grade / weekly tabs const Ranking = ({ profile }) => { const t = window.MP_I18N.t; const [scope, setScope] = React.useState('school'); const [rows, setRows] = React.useState([]); const [loading, setLoading] = React.useState(true); const [demo, setDemo] = React.useState(false); React.useEffect(() => { setLoading(true); window.MP_API.ranking(scope, profile).then(r => { setRows(r.rows || []); setDemo(!!r.demo); setLoading(false); }); }, [scope]); const tabs = [ { id: 'school', label: t('my_school') }, { id: 'global', label: t('global') }, { id: 'grade', label: t('grade_lvl') }, { id: 'weekly', label: t('weekly') } ]; return ( <>
๐Ÿ† {t('ranking')}
{profile.schoolCode && ( {t('school_code')}: {profile.schoolCode} )}
{tabs.map(tb => ( ))}
{loading ? (
โ€ฆ
) : rows.length === 0 ? (
{t('no_ranking_yet')}
) : (
{rows.slice(0, 30).map((r, i) => { const isMe = r.me || (r.first_name === profile.firstName && r.last_initial === profile.lastInitial); const rankCls = i === 0 ? 'r1' : i === 1 ? 'r2' : i === 2 ? 'r3' : ''; return (
{i < 3 ? ['๐Ÿฅ‡','๐Ÿฅˆ','๐Ÿฅ‰'][i] : i + 1}
{r.first_name} {r.last_initial}.
{r.school_name || 'โ€”'}{r.grade ? ' ยท ' + r.grade + 'ยฐ' : ''}
{r.total_points}
); })} {demo &&
โ˜… {window.MP_I18N.getLang()==='es' ? 'Datos de ejemplo (sin servidor)' : 'Demo data (no server)'}
}
)} ); }; window.Ranking = Ranking;