All files / web/src/constants practiceTypes.ts

89.18% Statements 66/74
100% Branches 1/1
0% Functions 0/2
89.18% Lines 66/74

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 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 751x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x             1x 1x 1x 1x 1x      
/**
 * Central definition of practice types used throughout the app.
 *
 * Add new practice types here - they'll be available in:
 * - Offline session logging
 * - Session plans
 * - Practice type filters
 * - Reporting/analytics
 */
 
export interface PracticeTypeConfig {
  /** Unique identifier - used in database and code */
  id: string
  /** Human-readable label */
  label: string
  /** Short description of the practice type */
  description: string
  /** Emoji icon for display */
  icon: string
}
 
/**
 * All available practice types.
 * Add new types here to make them available app-wide.
 */
export const PRACTICE_TYPES = [
  {
    id: 'abacus',
    label: 'Use Abacus',
    description: 'Physical abacus practice',
    icon: '🧮',
  },
  {
    id: 'visualization',
    label: 'Visualize',
    description: 'Mental math by visualizing beads',
    icon: '🧠',
  },
  {
    id: 'linear',
    label: 'Linear',
    description: 'Mental math with number sentences',
    icon: '📝',
  },
] as const satisfies readonly PracticeTypeConfig[]
 
/**
 * Union type of all valid practice type IDs.
 * Derived from PRACTICE_TYPES to ensure type safety.
 */
export type PracticeTypeId = (typeof PRACTICE_TYPES)[number]['id']
 
/**
 * Array of just the practice type IDs (useful for validation).
 */
export const PRACTICE_TYPE_IDS = PRACTICE_TYPES.map((t) => t.id) as PracticeTypeId[]
 
/**
 * Get a practice type config by ID.
 */
export function getPracticeType(id: PracticeTypeId): PracticeTypeConfig {
  const type = PRACTICE_TYPES.find((t) => t.id === id)
  if (!type) {
    throw new Error(`Unknown practice type: ${id}`)
  }
  return type
}
 
/**
 * Check if a string is a valid practice type ID.
 */
export function isValidPracticeTypeId(id: string): id is PracticeTypeId {
  return PRACTICE_TYPE_IDS.includes(id as PracticeTypeId)
}