File size: 1,058 Bytes
3092643
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/** Helpers to match hub cards with history quiz_id / topic_id. */

export function toIdSet(ids) {
  return new Set((ids || []).map((id) => String(id)))
}

export function mockTestCompletion(mt, completedIds) {
  const quizzes = mt?.quizzes || {}
  const fullId = quizzes.full?.id
  const fullCompleted = Boolean(fullId && completedIds.has(String(fullId)))
  const completedPartKeys = Object.entries(quizzes)
    .filter(([key]) => key.startsWith('part_'))
    .filter(([, meta]) => meta?.id && completedIds.has(String(meta.id)))
    .map(([key]) => key)
  const attempted = fullCompleted || completedPartKeys.length > 0
  return { fullCompleted, completedPartKeys, attempted }
}

export function writingSetCompletion(set, completedIds) {
  const task1Done = Boolean(set?.task1_topic_id && completedIds.has(String(set.task1_topic_id)))
  const task2Done = Boolean(set?.task2_topic_id && completedIds.has(String(set.task2_topic_id)))
  return {
    task1Done,
    task2Done,
    attempted: task1Done || task2Done,
    fullyDone: task1Done && task2Done,
  }
}