## Summary
When clicking the "Alternate" quick fill button in the "Edit Games" modal, the user can currently set games to alternate play/draw starting with
play first
(G1=play, G2=draw, G3=play, etc.).
Feature Request
: Clicking the "Alternate" button again should swap to the
opposite starting pattern
(G1=draw, G2=play, G3=draw, etc.), allowing users to quickly toggle between both alternation patterns.
---
## Current Behavior
The
applyAlternate()
function always starts with
play
on Game 1:
  • Click 1
    : G1=play, G2=draw, G3=play, G4=draw...
  • Click 2
    : Same as Click 1 (no change)
## Desired Behavior
The button should cycle through both alternation patterns:
  • Click 1
    : G1=play, G2=draw, G3=play, G4=draw... (starts with play)
  • Click 2
    : G1=draw, G2=play, G3=draw, G4=play... (starts with draw)
  • Click 3
    : Back to G1=play pattern
  • (repeats)
---
## Technical Context
### Files to Modify
  1. **
    apps/frontend/src/components/matches/forms/game-details-utils.ts
    **
- Current
applyAlternate()
function (lines 209-214) always returns games with
onPlay: idx % 2 === 0
-
Option A
: Add a new function
applyAlternateFromDraw()
that starts with draw
-
Option B
: Modify
applyAlternate()
to accept a
startWithPlay: boolean
parameter
  1. **
    apps/frontend/src/components/matches/forms/GameDetailsModal.tsx
    **
- The
handleAlternate()
handler (line 106) needs to detect the current pattern and swap to the opposite
- May need to add local state or use a ref to track which alternation pattern was last applied
- Alternatively, detect current pattern by checking
games[0].onPlay
value
  1. **
    apps/frontend/src/components/matches/forms/QuickFillButtons.tsx
    **
- The tooltip (line 116) says "Alternate - G1=play, G2=draw, G3=play, etc."
- Should update to indicate the cycling behavior, e.g., "Alternate - Toggle between play-first and draw-first patterns"
  1. **
    apps/frontend/src/components/matches/mobile/game-editing-sheet-mobile.tsx
    **
- Same change needed for mobile consistency (line 124)
- The button text "Alternate" (lines 192-201) may need a visual indicator of current state
### Recommended Implementation Approach
Detection-based approach
(simpler, no new state required):
```typescript
// In game-details-utils.ts - add new function
export function applyAlternate(games: GameEntry[], startWithPlay: boolean = true): GameEntry[] {
return games.map((g, idx) => ({
...g,
onPlay: startWithPlay ? idx % 2 === 0 : idx % 2 !== 0,
}));
}
// In GameDetailsModal.tsx - detect current pattern and swap
const handleAlternate = () => {
// Check if currently in play-first alternating pattern
const isPlayFirst = games.length > 0 && games[0].onPlay === true;
const isAlternating = games.every((g, idx) =>
g.onPlay === (idx % 2 === 0) || g.onPlay === (idx % 2 !== 0)
);
// If already alternating, swap starting position; otherwise default to play-first
const startWithPlay = isAlternating && isPlayFirst ? false : true;
onGamesChange(applyAlternate(games, startWithPlay));
};
### Type Definition Reference
```typescript
// From apps/frontend/src/components/matches/forms/types.ts
interface GameEntry {
id: string;
gameNumber: number;
winner: "me" | "opponent" | "draw";
onPlay?: boolean; // true = on play, false = on draw, undefined = unknown
player1Battlefield?: string | null;
player2Battlefield?: string | null;
}
---
## Acceptance Criteria
  • [ ] Clicking "Alternate" button the first time sets G1=play, G2=draw, G3=play pattern
  • [ ] Clicking "Alternate" button again swaps to G1=draw, G2=play, G3=draw pattern
  • [ ] Clicking a third time returns to the play-first pattern
  • [ ] Works correctly for any number of games (1-15)
  • [ ] Works in both desktop modal (
    GameDetailsModal.tsx
    ) and mobile sheet (
    game-editing-sheet-mobile.tsx
    )
  • [ ] Tooltip/label updated to indicate cycling behavior
  • [ ] If games are in a non-alternating state (e.g., all play or mixed), first click defaults to play-first pattern
---
## Questions for Stakeholder
  1. Visual feedback
    : Should the button show any visual indication of which alternation mode is currently active? (e.g., subtle icon change or toggle state)
  2. Default behavior
    : When games are in a completely random state (not alternating), should the first click always default to play-first, or should it detect the majority pattern?
  3. Edge case
    : If a user manually changes one game's play/draw after using Alternate, should the next Alternate click still cycle, or reset to play-first?
---
## Estimated Complexity
T-shirt Size: XS
(Extra Small)
This is a straightforward logic change in a single utility function with minimal UI updates. The implementation is well-isolated to the quick fill feature and has no backend changes required.