Files
LivingDexTracker/src/lib/utils/boxPlacement.ts
T
Josh Creek 3a2c18bbeb fix: repair defects surfaced by gating CI on lint and typecheck
`npm run check` reported 15 errors and `npm run lint` 20, all pre-existing, so
neither gate could pass. Fixing them turned up three real bugs:

- SignOut destructured `{ error }` off `.then(() => {})`, which resolves to
  undefined, so every sign-out threw a TypeError - after the signed-out event had
  already been emitted. Sign-out also left the user on the protected page they
  were on, still showing its content; it now returns them to the home page and
  re-runs the server loads.

- SignUp passed `redirectTo`, which is not a signUp option and was silently
  ignored, so the confirmation link has always used Supabase's configured site
  URL. Documented rather than changed, since pointing it elsewhere needs an
  absolute allow-listed URL.

- The Pokédex page tracked totalRecordsCreated but never passed it to the box
  view, so the "Processed N entries so far" progress message never rendered.

The rest is typing and dead code: cookie callback parameters in hooks.server.ts
and +layout.ts, the untyped supabase props, a query-builder type that made
PostgREST rows untyped downstream, an unused session destructure, and
`while (true)` paging loops rewritten as `for (;;)`.
2026-09-13 17:38:42 +01:00

41 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Calculate box placement for Pokémon based on their position in a sorted list
*
* Box layout: 6 columns × 5 rows = 30 Pokémon per box
*
* @param index - Zero-based index in the sorted list
* @returns Box placement with box number, row, and column (1-indexed)
*/
export function calculateBoxPlacement(index: number): {
box: number;
row: number;
column: number;
} {
const POKEMON_PER_BOX = 30;
const COLUMNS_PER_BOX = 6;
// Calculate which box this Pokémon belongs to (1-indexed)
const box = Math.floor(index / POKEMON_PER_BOX) + 1;
// Calculate position within the box (0-indexed)
const positionInBox = index % POKEMON_PER_BOX;
// Calculate row and column (1-indexed)
const row = Math.floor(positionInBox / COLUMNS_PER_BOX) + 1;
const column = (positionInBox % COLUMNS_PER_BOX) + 1;
return { box, row, column };
}
/**
* Calculate all unique box numbers needed for a list of Pokémon
*
* @param count - Total number of Pokémon
* @returns Array of box numbers (1-indexed)
*/
export function calculateBoxNumbers(count: number): number[] {
const POKEMON_PER_BOX = 30;
const totalBoxes = Math.ceil(count / POKEMON_PER_BOX);
return Array.from({ length: totalBoxes }, (_, i) => i + 1);
}