File size: 2,393 Bytes
d15f07c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Shared mapping between the personalized-feed backend slugs and the frontend
// StoryLenses tile ids. The backend (api/routes/feed) speaks a different
// vocabulary than the homepage tiles, so we translate at the wire boundary.
//
// Keep these maps in lock-step with:
//   - StoryLenses.tsx  LENSES        (signal tiles: contested/money/flags/soon/next)
//   - StoryLenses.tsx  VALUE_FRAMES  (value-frames: family/faith/charitable/…)
//   - api ALLOWED_SIGNALS / ALLOWED_LENSES

// ---- Signals (StoryLenses LENSES tiles) --------------------------------------
// Backend slug <-> frontend tile id. Backend also allows "slipped-through" and
// "helping-hands", which have NO frontend tile — those are intentionally absent
// here so fromSignalSlug() drops them gracefully when seeding the strip.
const SIGNAL_SLUG_TO_ID: Record<string, string> = {
  contested: 'contested',
  'money-moves': 'money',
  'raised-eyebrows': 'flags',
  'moving-fast': 'soon',
  'watch-next': 'next',
}

const SIGNAL_ID_TO_SLUG: Record<string, string> = Object.fromEntries(
  Object.entries(SIGNAL_SLUG_TO_ID).map(([slug, id]) => [id, slug]),
)

/** Frontend signal tile id -> backend signal slug (e.g. 'money' -> 'money-moves'). */
export function toSignalSlug(id: string): string | undefined {
  return SIGNAL_ID_TO_SLUG[id]
}

/** Backend signal slug -> frontend tile id; `undefined` for unmapped slugs. */
export function fromSignalSlug(slug: string): string | undefined {
  return SIGNAL_SLUG_TO_ID[slug]
}

// ---- Value-frames (StoryLenses VALUE_FRAMES) ---------------------------------
// Backend "lenses" (value-frames) slug <-> frontend value-frame id.
const LENS_SLUG_TO_ID: Record<string, string> = {
  'family-first': 'family',
  'faith-community': 'faith',
  'charitable-impact': 'charitable',
  'neighborhood-life': 'neighborhood',
  education: 'education',
  'local-economy': 'economy',
}

const LENS_ID_TO_SLUG: Record<string, string> = Object.fromEntries(
  Object.entries(LENS_SLUG_TO_ID).map(([slug, id]) => [id, slug]),
)

/** Frontend value-frame id -> backend lens slug (e.g. 'family' -> 'family-first'). */
export function toLensSlug(id: string): string | undefined {
  return LENS_ID_TO_SLUG[id]
}

/** Backend lens slug -> frontend value-frame id; `undefined` for unmapped slugs. */
export function fromLensSlug(slug: string): string | undefined {
  return LENS_SLUG_TO_ID[slug]
}