Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/leaderboard/MinersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export const MinersList: React.FC<MinersListProps> = ({
header: 'Miner',
width: '25%',
cellSx: { pl: 1.5 },
sortKey: 'username',
renderCell: (miner) => <MinerIdentityCell miner={miner} />,
},
{
Expand Down
36 changes: 26 additions & 10 deletions src/components/leaderboard/TopMinersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
type SortOption,
type LeaderboardVariant,
FONTS,
minerSortName,
} from './types';

type ViewMode = 'cards' | 'list';
Expand Down Expand Up @@ -97,7 +98,14 @@ interface TopMinersTableProps {

const getAllowedSortOptions = (variant: LeaderboardVariant): SortOption[] => {
if (variant === 'discoveries')
return ['totalScore', 'usdPerDay', 'totalIssues', 'credibility', 'watch'];
return [
'totalScore',
'usdPerDay',
'totalIssues',
'credibility',
'username',
'watch',
];
if (variant === 'watchlist')
return [
'totalScore',
Expand All @@ -106,9 +114,17 @@ const getAllowedSortOptions = (variant: LeaderboardVariant): SortOption[] => {
'totalIssues',
'issueDiscoveryScore',
'credibility',
'username',
'watch',
];
return ['totalScore', 'usdPerDay', 'totalPRs', 'credibility', 'watch'];
return [
'totalScore',
'usdPerDay',
'totalPRs',
'credibility',
'username',
'watch',
];
};

type EligibilityFilter = 'all' | 'eligible' | 'ineligible';
Expand Down Expand Up @@ -198,6 +214,8 @@ const compareMiners = (
);
case 'credibility':
return (a.credibility ?? 0) - (b.credibility ?? 0);
case 'username':
return minerSortName(a).localeCompare(minerSortName(b));
case 'watch':
return compareByWatchlist(a, b, (m) => m.githubId, isWatched);
default:
Expand Down Expand Up @@ -278,6 +296,7 @@ const TopMinersTable: React.FC<TopMinersTableProps> = ({
} = useDataTableParams<SortOption, TopMinersUrlFilters>({
sortKeys: allowedSortKeys,
defaultSortKey: 'totalScore',
defaultOrderOverrides: { username: 'asc' },
// Reuse the hook's `page` slot for our "show more" count — setSort and
// filter changes reset it, which is the behavior we want.
paramKeys: { page: VISIBLE_QUERY_PARAM },
Expand Down Expand Up @@ -349,11 +368,7 @@ const TopMinersTable: React.FC<TopMinersTableProps> = ({

if (searchQuery) {
const lowerQuery = searchQuery.toLowerCase();
result = result.filter(
(m) =>
m.githubId?.toLowerCase().includes(lowerQuery) ||
m.author?.toLowerCase().includes(lowerQuery),
);
result = result.filter((m) => minerSortName(m).includes(lowerQuery));
}

result = result.filter((m) => {
Expand Down Expand Up @@ -616,14 +631,15 @@ const getSortButtonOptions = (
};
const credibility = { label: 'Credibility', value: 'credibility' as const };
const score = { label: scoreLabel, value: 'totalScore' as const };
const name = { label: 'Name', value: 'username' as const };

if (variant === 'watchlist') {
return [score, discovery, earnings, prs, issues, credibility];
return [score, discovery, earnings, prs, issues, credibility, name];
}
if (variant === 'discoveries') {
return [score, earnings, issues, credibility];
return [score, earnings, issues, credibility, name];
}
return [score, earnings, prs, credibility];
return [score, earnings, prs, credibility, name];
};

const SortButtons: React.FC<SortButtonsProps> = ({
Expand Down
8 changes: 7 additions & 1 deletion src/components/leaderboard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ export { default as TopRepositoriesTable } from './TopRepositoriesTable';
export { ActivitySidebarCards } from './ActivitySidebarCards';

// Types and utilities
export type { MinerStats } from './types';
export {
FONTS,
getRankColors,
minerSortName,
type SortOption,
type MinerStats,
} from './types';
12 changes: 12 additions & 0 deletions src/components/leaderboard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,20 @@ export type SortOption =
| 'totalIssues'
| 'issueDiscoveryScore'
| 'credibility'
| 'username'
| 'watch';

const isNumericGithubId = (value?: string) => !value || /^\d+$/.test(value);

/** Sort/search key aligned with MinerIdentityCell: login when known, else githubId. */
export const minerSortName = (miner: MinerStats): string => {
const name =
!isNumericGithubId(miner.author) && miner.author
? miner.author
: miner.githubId;
return (name ?? '').toLowerCase();
};

export const FONTS = {
mono: '"JetBrains Mono", monospace',
} as const;
Expand Down
Loading