All files / web/src/components/create/abacus studio-url.ts

100% Statements 16/16
100% Branches 5/5
100% Functions 1/1
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 171x 1x 1x 1x 1x 1x 1x 44x 44x 44x 44x 44x 44x 44x 44x 44x  
/**
 * /create/abacus URL assembly (Gitea #22). The studio's address carries two
 * independent selections — WHOSE abacus (?player=) and WHICH saved design
 * (?design=) — so changing one must never drop the other: picking a student
 * inside a restored design keeps the design in the URL, and vice versa.
 */
export function studioHref(
  pathname: string,
  opts: { playerId: string | null; designId: string | null }
): string {
  const qs = new URLSearchParams()
  if (opts.designId) qs.set('design', opts.designId)
  if (opts.playerId) qs.set('player', opts.playerId)
  const search = qs.toString()
  return search ? `${pathname}?${search}` : pathname
}