2026-03-02 13:18:47 -08:00
|
|
|
import { memo, useMemo } from "react";
|
2025-10-25 03:23:41 -07:00
|
|
|
import { Badge } from "~/components/ui/badge";
|
|
|
|
|
|
|
|
|
|
interface TeamsDraftedGridProps {
|
|
|
|
|
draftSlots: Array<{
|
|
|
|
|
id: string;
|
|
|
|
|
team: {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
};
|
|
|
|
|
}>;
|
2026-02-22 16:56:07 -08:00
|
|
|
ownerMap?: Record<string, string>;
|
2025-10-25 03:23:41 -07:00
|
|
|
picks: Array<{
|
|
|
|
|
id: string;
|
|
|
|
|
team: {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
};
|
|
|
|
|
participant: {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
};
|
|
|
|
|
sport: {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
};
|
|
|
|
|
}>;
|
2026-02-20 21:26:27 -08:00
|
|
|
sports: Array<{
|
2025-10-25 03:23:41 -07:00
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
}>;
|
|
|
|
|
season: {
|
|
|
|
|
numFlexPicks: number;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-02 13:18:47 -08:00
|
|
|
export const TeamsDraftedGrid = memo(function TeamsDraftedGrid({
|
2025-10-25 03:23:41 -07:00
|
|
|
draftSlots,
|
|
|
|
|
picks,
|
2026-02-20 21:26:27 -08:00
|
|
|
sports,
|
2025-10-25 03:23:41 -07:00
|
|
|
season,
|
2026-02-22 16:56:07 -08:00
|
|
|
ownerMap = {},
|
2025-10-25 03:23:41 -07:00
|
|
|
}: TeamsDraftedGridProps) {
|
|
|
|
|
// Calculate picks by team and sport
|
|
|
|
|
const picksByTeamAndSport = useMemo(() => {
|
|
|
|
|
const map = new Map<string, Map<string, typeof picks>>();
|
|
|
|
|
|
|
|
|
|
picks.forEach((pick) => {
|
|
|
|
|
if (!map.has(pick.team.id)) {
|
|
|
|
|
map.set(pick.team.id, new Map());
|
|
|
|
|
}
|
Fix oxlint warnings: no-shadow, consistent-function-scoping, no-non-null-assertion, and others (#196)
* Fix no-shadow and consistent-function-scoping lint violations
Resolves all 11 no-shadow and 16 consistent-function-scoping oxlint
warnings and promotes both rules to errors in .oxlintrc.json.
no-shadow: renamed Drizzle callback params (sports→s, matches→m,
seasons→s) to avoid shadowing outer imports; removed shadowed
destructures (eq, inArray) from where callbacks; renamed inner
template→bracketTemplate, prev→currentTimers, season→ss, name→teamName
(with name: teamName fix to preserve semantics).
consistent-function-scoping: moved formatDate, getRankBadge,
getMovementIndicator, getPositionBadge, getStatusBadge, toDateStr,
elo (×2), weightedPick, sortByMatchNumber (×2) to module scope;
moved formatTime (×2), isValidLeagueName, getDraftTimes,
makeSeasonQueues to file scope in test files.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix no-non-null-assertion lint violations and promote to error
Eliminates all 208 no-non-null-assertion warnings across 38 files.
Promotes typescript/no-non-null-assertion from warn to error in
.oxlintrc.json.
Fix patterns applied:
- Map.get(key)! after .has() check → extract with get() + null guard
- Map.get(key)! on pre-populated count maps → ?? 0 default
- .set(id, map.get(id)! + 1) increment → ?? 0 before adding
- participant1Id!/participant2Id! on DB matches → ?? "" fallback
- array.find()! in tests → guard + throw or expect().toBeDefined()
- bracketTemplateCache.get(id)! → null guard extract
- Various nullable field accesses → optional chain or ?? default
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix prefer-add-event-listener, no-unassigned-import, require-module-specifiers
Resolves all 9 remaining non-console lint warnings and promotes all
three rules to errors in .oxlintrc.json.
- prefer-add-event-listener: converted onchange/onclick/onload
assignments to addEventListener in useDraftNotifications.ts and
admin.data-sync.tsx; stored changeHandler ref for proper cleanup
with removeEventListener
- no-unassigned-import: configured rule with allow list for legitimate
side-effect imports (*.css, @testing-library/jest-dom,
@testing-library/cypress/add-commands)
- require-module-specifiers: removed redundant `export {}` from
cypress/support/e2e.ts (file already has an import)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix TypeScript errors from no-non-null-assertion fixes
Two fixes introduced by the non-null assertion cleanup produced type
errors:
- scoring-event.ts: `?? ""` was wrong type for a participant object map;
restructured to explicit null guards so TypeScript can narrow correctly
- standings-sync/index.ts: `?? null` after name-match lookup lost the
truthy guarantee, causing TS18047 on the write-back block; added
`participant &&` guard before accessing its properties
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Add npm run typecheck as Stop hook in Claude settings
Runs a full project typecheck at the end of each Claude turn so type
errors surface as feedback before the next message.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 10:59:51 -07:00
|
|
|
const teamMap = map.get(pick.team.id) ?? new Map<string, typeof picks>();
|
|
|
|
|
if (!map.has(pick.team.id)) map.set(pick.team.id, teamMap);
|
2025-10-25 03:23:41 -07:00
|
|
|
if (!teamMap.has(pick.sport.id)) {
|
|
|
|
|
teamMap.set(pick.sport.id, []);
|
|
|
|
|
}
|
Fix oxlint warnings: no-shadow, consistent-function-scoping, no-non-null-assertion, and others (#196)
* Fix no-shadow and consistent-function-scoping lint violations
Resolves all 11 no-shadow and 16 consistent-function-scoping oxlint
warnings and promotes both rules to errors in .oxlintrc.json.
no-shadow: renamed Drizzle callback params (sports→s, matches→m,
seasons→s) to avoid shadowing outer imports; removed shadowed
destructures (eq, inArray) from where callbacks; renamed inner
template→bracketTemplate, prev→currentTimers, season→ss, name→teamName
(with name: teamName fix to preserve semantics).
consistent-function-scoping: moved formatDate, getRankBadge,
getMovementIndicator, getPositionBadge, getStatusBadge, toDateStr,
elo (×2), weightedPick, sortByMatchNumber (×2) to module scope;
moved formatTime (×2), isValidLeagueName, getDraftTimes,
makeSeasonQueues to file scope in test files.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix no-non-null-assertion lint violations and promote to error
Eliminates all 208 no-non-null-assertion warnings across 38 files.
Promotes typescript/no-non-null-assertion from warn to error in
.oxlintrc.json.
Fix patterns applied:
- Map.get(key)! after .has() check → extract with get() + null guard
- Map.get(key)! on pre-populated count maps → ?? 0 default
- .set(id, map.get(id)! + 1) increment → ?? 0 before adding
- participant1Id!/participant2Id! on DB matches → ?? "" fallback
- array.find()! in tests → guard + throw or expect().toBeDefined()
- bracketTemplateCache.get(id)! → null guard extract
- Various nullable field accesses → optional chain or ?? default
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix prefer-add-event-listener, no-unassigned-import, require-module-specifiers
Resolves all 9 remaining non-console lint warnings and promotes all
three rules to errors in .oxlintrc.json.
- prefer-add-event-listener: converted onchange/onclick/onload
assignments to addEventListener in useDraftNotifications.ts and
admin.data-sync.tsx; stored changeHandler ref for proper cleanup
with removeEventListener
- no-unassigned-import: configured rule with allow list for legitimate
side-effect imports (*.css, @testing-library/jest-dom,
@testing-library/cypress/add-commands)
- require-module-specifiers: removed redundant `export {}` from
cypress/support/e2e.ts (file already has an import)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix TypeScript errors from no-non-null-assertion fixes
Two fixes introduced by the non-null assertion cleanup produced type
errors:
- scoring-event.ts: `?? ""` was wrong type for a participant object map;
restructured to explicit null guards so TypeScript can narrow correctly
- standings-sync/index.ts: `?? null` after name-match lookup lost the
truthy guarantee, causing TS18047 on the write-back block; added
`participant &&` guard before accessing its properties
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Add npm run typecheck as Stop hook in Claude settings
Runs a full project typecheck at the end of each Claude turn so type
errors surface as feedback before the next message.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 10:59:51 -07:00
|
|
|
teamMap.get(pick.sport.id)?.push(pick);
|
2025-10-25 03:23:41 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
}, [picks]);
|
|
|
|
|
|
|
|
|
|
// Calculate flex picks used by each team
|
|
|
|
|
const flexPicksByTeam = useMemo(() => {
|
|
|
|
|
const map = new Map<string, number>();
|
|
|
|
|
|
|
|
|
|
draftSlots.forEach((slot) => {
|
|
|
|
|
const teamPicks = picks.filter((p) => p.team.id === slot.team.id);
|
2026-02-20 21:26:27 -08:00
|
|
|
const uniqueSportsPicked = new Set(teamPicks.map((p) => p.sport.id)).size;
|
|
|
|
|
const flexUsed = Math.max(0, teamPicks.length - uniqueSportsPicked);
|
2025-10-25 03:23:41 -07:00
|
|
|
map.set(slot.team.id, flexUsed);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return map;
|
2026-02-20 21:26:27 -08:00
|
|
|
}, [picks, draftSlots]);
|
2025-10-25 03:23:41 -07:00
|
|
|
|
|
|
|
|
if (sports.length === 0) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex items-center justify-center h-full p-8 text-muted-foreground">
|
2026-02-20 21:26:27 -08:00
|
|
|
<p>No sports have been configured for this season.</p>
|
2025-10-25 03:23:41 -07:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="w-full h-full overflow-auto">
|
2025-10-25 18:25:26 -07:00
|
|
|
<table className="w-full border-collapse">
|
2025-10-25 03:23:41 -07:00
|
|
|
<thead className="sticky top-0 bg-background z-10">
|
|
|
|
|
<tr>
|
2026-02-22 22:36:12 -08:00
|
|
|
<th className="border-r border-b border-border p-2 text-left font-semibold min-w-[150px] bg-muted/50 sticky left-0 z-20">
|
2025-10-25 03:23:41 -07:00
|
|
|
Sport
|
|
|
|
|
</th>
|
2025-10-25 18:25:26 -07:00
|
|
|
{draftSlots.map((slot, index) => {
|
2025-10-25 03:23:41 -07:00
|
|
|
const flexUsed = flexPicksByTeam.get(slot.team.id) || 0;
|
2025-10-25 18:25:26 -07:00
|
|
|
const isLast = index === draftSlots.length - 1;
|
2025-10-25 03:23:41 -07:00
|
|
|
return (
|
|
|
|
|
<th
|
|
|
|
|
key={slot.id}
|
2025-10-25 18:25:26 -07:00
|
|
|
className={`border-b border-border p-2 text-left font-semibold min-w-[180px] bg-muted/50 ${!isLast ? 'border-r' : ''}`}
|
2025-10-25 03:23:41 -07:00
|
|
|
>
|
|
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
|
<div className="font-semibold text-sm">
|
2026-02-22 16:56:07 -08:00
|
|
|
{ownerMap[slot.team.id] || slot.team.name}
|
2025-10-25 03:23:41 -07:00
|
|
|
</div>
|
|
|
|
|
<div className="text-xs text-muted-foreground font-normal">
|
|
|
|
|
{flexUsed} of {season.numFlexPicks} flex
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</th>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
2025-10-25 18:25:26 -07:00
|
|
|
<tbody className="border-b border-border">
|
|
|
|
|
{sports.map((sport, sportIndex) => {
|
|
|
|
|
const isLastRow = sportIndex === sports.length - 1;
|
|
|
|
|
return (
|
|
|
|
|
<tr key={sport.id}>
|
2026-02-22 22:36:12 -08:00
|
|
|
<td className={`border-r border-border p-2 font-medium bg-muted/30 sticky left-0 z-10 ${!isLastRow ? 'border-b' : ''}`}>
|
2025-10-25 18:25:26 -07:00
|
|
|
{sport.name}
|
|
|
|
|
</td>
|
|
|
|
|
{draftSlots.map((slot, slotIndex) => {
|
|
|
|
|
const teamSportPicks =
|
|
|
|
|
picksByTeamAndSport
|
|
|
|
|
.get(slot.team.id)
|
|
|
|
|
?.get(sport.id) || [];
|
|
|
|
|
const hasMultiplePicks = teamSportPicks.length > 1;
|
|
|
|
|
const isLastCol = slotIndex === draftSlots.length - 1;
|
2025-10-25 03:23:41 -07:00
|
|
|
|
2025-10-25 18:25:26 -07:00
|
|
|
return (
|
|
|
|
|
<td
|
|
|
|
|
key={`${slot.team.id}-${sport.id}`}
|
|
|
|
|
className={`border-border p-2 ${
|
|
|
|
|
hasMultiplePicks
|
|
|
|
|
? "bg-accent/30 font-semibold"
|
|
|
|
|
: "bg-background"
|
|
|
|
|
} ${!isLastRow ? 'border-b' : ''} ${!isLastCol ? 'border-r' : ''}`}
|
|
|
|
|
>
|
2025-10-25 03:23:41 -07:00
|
|
|
{teamSportPicks.length > 0 ? (
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2026-02-20 21:26:27 -08:00
|
|
|
{teamSportPicks.map((pick, i) => (
|
2025-10-25 03:23:41 -07:00
|
|
|
<div
|
|
|
|
|
key={pick.id}
|
|
|
|
|
className="text-sm flex items-center gap-1"
|
|
|
|
|
>
|
|
|
|
|
<span>{pick.participant.name}</span>
|
|
|
|
|
{hasMultiplePicks && (
|
|
|
|
|
<Badge
|
|
|
|
|
variant="secondary"
|
|
|
|
|
className="text-xs px-1 py-0"
|
|
|
|
|
>
|
2026-02-20 21:26:27 -08:00
|
|
|
{i + 1}
|
2025-10-25 03:23:41 -07:00
|
|
|
</Badge>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</td>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2025-10-25 18:25:26 -07:00
|
|
|
</tr>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2025-10-25 03:23:41 -07:00
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2026-03-02 13:18:47 -08:00
|
|
|
});
|