All files / web/src/lib/share urls.ts

71.69% Statements 38/53
75% Branches 6/8
66.66% Functions 2/3
71.69% Lines 38/53

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 541x 1x 1x 1x 1x 1x 1x 1x 1x 1x 24x 24x 24x 24x   24x 1x 1x 1x 1x 1x 24x 24x 24x 21x 24x 1x 24x 1x 24x 1x 24x   24x 24x 1x 1x 1x 1x 1x                            
/**
 * URL helpers for share codes
 */
 
export type ShareType = 'classroom' | 'family' | 'room' | 'observe' | 'song'
 
/**
 * Get the base URL for the current environment
 * Uses window.location.origin on client, falls back to env var or default
 */
function getBaseUrl(): string {
  if (typeof window !== 'undefined') {
    return window.location.origin
  }
  return process.env.NEXT_PUBLIC_APP_URL || 'https://abaci.one'
}
 
/**
 * Generate a shareable URL for a given code type
 */
export function getShareUrl(type: ShareType, code: string): string {
  const base = getBaseUrl()
  switch (type) {
    case 'classroom':
      return `${base}/join/classroom/${code}`
    case 'family':
      return `${base}/join/family/${code}`
    case 'room':
      return `${base}/arcade/join/${code}`
    case 'observe':
      return `${base}/observe/${code}`
    case 'song':
      return `${base}/song/${code}`
  }
}
 
/**
 * Get human-readable label for share type
 */
export function getShareTypeLabel(type: ShareType): string {
  switch (type) {
    case 'classroom':
      return 'Classroom'
    case 'family':
      return 'Family'
    case 'room':
      return 'Room'
    case 'observe':
      return 'Session'
    case 'song':
      return 'Song'
  }
}