@magmamath/students-features 1.3.11 → 1.3.12-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/commonjs/features/pmProgress/components/chart/components/SlicesPaths.js +1 -1
  2. package/dist/commonjs/features/pmProgress/components/chart/components/SlicesPaths.js.map +1 -1
  3. package/dist/commonjs/features/pmProgress/components/header/NextUp.js +5 -9
  4. package/dist/commonjs/features/pmProgress/components/header/NextUp.js.map +1 -1
  5. package/dist/commonjs/features/pmProgress/components/insights/PmInsights.js +1 -1
  6. package/dist/commonjs/features/pmProgress/components/insights/PmInsights.js.map +1 -1
  7. package/dist/commonjs/features/pmProgress/components/list/PmDomainList.js +1 -1
  8. package/dist/commonjs/features/pmProgress/components/list/PmDomainList.js.map +1 -1
  9. package/dist/commonjs/features/pmProgress/components/standard/StandardTag.js +1 -1
  10. package/dist/commonjs/features/pmProgress/components/standard/StandardTag.js.map +1 -1
  11. package/dist/commonjs/features/pmProgress/hooks/useNextUpDomain.js +42 -0
  12. package/dist/commonjs/features/pmProgress/hooks/useNextUpDomain.js.map +1 -0
  13. package/dist/commonjs/features/pmProgress/model/PmTreeModel.js +18 -16
  14. package/dist/commonjs/features/pmProgress/model/PmTreeModel.js.map +1 -1
  15. package/dist/commonjs/features/pmProgress/shared/pmProgress.helpers.js +6 -2
  16. package/dist/commonjs/features/pmProgress/shared/pmProgress.helpers.js.map +1 -1
  17. package/dist/module/features/pmProgress/components/chart/components/SlicesPaths.js +1 -1
  18. package/dist/module/features/pmProgress/components/chart/components/SlicesPaths.js.map +1 -1
  19. package/dist/module/features/pmProgress/components/header/NextUp.js +6 -10
  20. package/dist/module/features/pmProgress/components/header/NextUp.js.map +1 -1
  21. package/dist/module/features/pmProgress/components/insights/PmInsights.js +1 -1
  22. package/dist/module/features/pmProgress/components/insights/PmInsights.js.map +1 -1
  23. package/dist/module/features/pmProgress/components/list/PmDomainList.js +1 -1
  24. package/dist/module/features/pmProgress/components/list/PmDomainList.js.map +1 -1
  25. package/dist/module/features/pmProgress/components/standard/StandardTag.js +1 -1
  26. package/dist/module/features/pmProgress/components/standard/StandardTag.js.map +1 -1
  27. package/dist/module/features/pmProgress/hooks/useNextUpDomain.js +37 -0
  28. package/dist/module/features/pmProgress/hooks/useNextUpDomain.js.map +1 -0
  29. package/dist/module/features/pmProgress/model/PmTreeModel.js +20 -18
  30. package/dist/module/features/pmProgress/model/PmTreeModel.js.map +1 -1
  31. package/dist/module/features/pmProgress/shared/pmProgress.helpers.js +2 -0
  32. package/dist/module/features/pmProgress/shared/pmProgress.helpers.js.map +1 -1
  33. package/dist/typescript/commonjs/features/pmProgress/components/header/NextUp.d.ts.map +1 -1
  34. package/dist/typescript/commonjs/features/pmProgress/hooks/useNextUpDomain.d.ts +5 -0
  35. package/dist/typescript/commonjs/features/pmProgress/hooks/useNextUpDomain.d.ts.map +1 -0
  36. package/dist/typescript/commonjs/features/pmProgress/model/PmTreeModel.d.ts +3 -3
  37. package/dist/typescript/commonjs/features/pmProgress/model/PmTreeModel.d.ts.map +1 -1
  38. package/dist/typescript/commonjs/features/pmProgress/shared/pmProgress.helpers.d.ts +4 -0
  39. package/dist/typescript/commonjs/features/pmProgress/shared/pmProgress.helpers.d.ts.map +1 -1
  40. package/dist/typescript/module/features/pmProgress/components/header/NextUp.d.ts.map +1 -1
  41. package/dist/typescript/module/features/pmProgress/hooks/useNextUpDomain.d.ts +5 -0
  42. package/dist/typescript/module/features/pmProgress/hooks/useNextUpDomain.d.ts.map +1 -0
  43. package/dist/typescript/module/features/pmProgress/model/PmTreeModel.d.ts +3 -3
  44. package/dist/typescript/module/features/pmProgress/model/PmTreeModel.d.ts.map +1 -1
  45. package/dist/typescript/module/features/pmProgress/shared/pmProgress.helpers.d.ts +4 -0
  46. package/dist/typescript/module/features/pmProgress/shared/pmProgress.helpers.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/src/features/pmProgress/components/chart/components/SlicesPaths.tsx +1 -1
  49. package/src/features/pmProgress/components/header/NextUp.tsx +6 -13
  50. package/src/features/pmProgress/components/insights/PmInsights.tsx +1 -1
  51. package/src/features/pmProgress/components/list/PmDomainList.tsx +1 -1
  52. package/src/features/pmProgress/components/standard/StandardTag.tsx +1 -1
  53. package/src/features/pmProgress/hooks/useNextUpDomain.ts +31 -0
  54. package/src/features/pmProgress/model/PmTreeModel.ts +26 -17
  55. package/src/features/pmProgress/shared/pmProgress.helpers.ts +11 -0
@@ -4,33 +4,26 @@ import { COLORS, HeadingVariants, SPACING, Typography } from '@magmamath/react-n
4
4
  import { SketchArrowRight } from '../../../../shared/icons/SketchArrowRight'
5
5
  import { SliceDiamondIcon } from '../../../../shared/icons/SliceDiamondIcon'
6
6
  import { useText } from '../../../../shared/translation'
7
- import { useUnit, useStoreMap } from 'effector-react'
7
+ import { useUnit } from 'effector-react'
8
8
  import { usePmProgress } from '../../context/PmProgressContext'
9
- import { isFluencyDomain } from '../../shared/pmProgress.helpers'
10
9
  import { OpeningLoaderId, SolvingFlow } from '../../shared/pmProgress.constants'
11
10
  import { StartButton } from './StartButton'
11
+ import { useNextUpDomain } from '../../hooks/useNextUpDomain'
12
12
 
13
13
  export const NextUp = () => {
14
14
  const t = useText()
15
15
  const { model, onStartPress } = usePmProgress()
16
+ const nextUp = useNextUpDomain()
16
17
 
17
18
  const status = useUnit(model.tree.$status)
18
19
  const loaderOpeningId = useUnit(model.solving.$loaderOpeningId)
19
20
 
20
- const nextUp = useStoreMap(model.tree.$domains, (domains) =>
21
- domains.find((domain) => {
22
- const isFluency = isFluencyDomain(domain.title)
23
- const isDomainCompleted = domain.standards.every((standard) => standard.isCompleted)
24
- return !isFluency && !isDomainCompleted
25
- }),
26
- )
27
-
28
21
  const isLoading = loaderOpeningId === OpeningLoaderId.START_BUTTON
29
22
  const isSkillOpeningActionPending = !!(loaderOpeningId !== null || status)
30
23
 
31
24
  return (
32
25
  <View style={styles.container}>
33
- {nextUp && !status && (
26
+ {nextUp.domain && !status && (
34
27
  <>
35
28
  <View style={styles.content}>
36
29
  <View style={styles.subtitle}>
@@ -40,10 +33,10 @@ export const NextUp = () => {
40
33
  </View>
41
34
  <View style={[styles.row, styles.tilted]}>
42
35
  <Typography variant={HeadingVariants.H7} style={styles.muted}>
43
- {nextUp?.title}
36
+ {nextUp.domain.title}
44
37
  </Typography>
45
38
  <View style={styles.diamond}>
46
- <SliceDiamondIcon color={nextUp?.color} />
39
+ <SliceDiamondIcon color={nextUp.domain.color} />
47
40
  </View>
48
41
  </View>
49
42
  </View>
@@ -15,7 +15,7 @@ import {
15
15
  export const PmInsights = () => {
16
16
  const { model } = usePmProgress()
17
17
  const [chartSize, setChartSize] = useState(MAX_PIE_CHART_SIZE)
18
- const chartData = useStoreMap(model.tree.$domains, (domains) =>
18
+ const chartData = useStoreMap(model.tree.$domainsInGrade, (domains) =>
19
19
  domains.map((domain) => ({
20
20
  value: 1,
21
21
  fillPercent: Math.round(domain.scorePercentage),
@@ -11,7 +11,7 @@ import { SolvingFlow } from '../../shared/pmProgress.constants'
11
11
 
12
12
  export const PmDomainList = () => {
13
13
  const { model, onStandardPress } = usePmProgress()
14
- const domains = useUnit(model.tree.$domains)
14
+ const domains = useUnit(model.tree.$domainsInGrade)
15
15
  const expandedId = useUnit(model.highlight.$expandedId)
16
16
  const hoveredId = useUnit(model.highlight.$hoveredId)
17
17
  const loaderOpeningId = useUnit(model.solving.$loaderOpeningId)
@@ -118,7 +118,7 @@ type StandardTagProps = {
118
118
 
119
119
  export const StandardTag = ({ skillId, model }: StandardTagProps) => {
120
120
  const standardInfo = useStoreMap({
121
- store: model.tree.$domains,
121
+ store: model.tree.$domainsInGrade,
122
122
  keys: [skillId],
123
123
  fn: (domains, [skillId]) => {
124
124
  const domain = domains.find((d) => d.standards.some((s) => s.skillIds.includes(skillId)))
@@ -0,0 +1,31 @@
1
+ import { useUnit, useStoreMap } from 'effector-react'
2
+ import { usePmProgress } from '../context/PmProgressContext'
3
+ import { findDomainBySkillId, isFluencyDomain } from '../shared/pmProgress.helpers'
4
+
5
+ export const useNextUpDomain = () => {
6
+ const { model } = usePmProgress()
7
+ const magmaRecs = useUnit(model.recommendations.$magma)
8
+ const domainsInTree = useUnit(model.tree.$domains)
9
+
10
+ return useStoreMap({
11
+ store: model.tree.$domainsInGrade,
12
+ keys: [magmaRecs, domainsInTree],
13
+ fn: (domainsInGrade) => {
14
+ const firstRec = magmaRecs.items[0]
15
+ if (firstRec) {
16
+ const allDomains = Object.values(domainsInTree).flat()
17
+ const domain = findDomainBySkillId(firstRec._id, allDomains) ?? null
18
+ return { domain, isFromRecommendation: true }
19
+ }
20
+
21
+ const domain =
22
+ domainsInGrade.find((domain) => {
23
+ const isFluency = isFluencyDomain(domain.title)
24
+ const isDomainCompleted = domain.standards.every((standard) => standard.isCompleted)
25
+ return !isFluency && !isDomainCompleted
26
+ }) ?? null
27
+
28
+ return { domain, isFromRecommendation: false }
29
+ },
30
+ })
31
+ }
@@ -1,4 +1,4 @@
1
- import { attach, createEffect, createEvent, createStore, restore, sample } from 'effector'
1
+ import { attach, combine, createEffect, createEvent, createStore, restore, sample } from 'effector'
2
2
  import { createAction } from 'effector-action'
3
3
  import {
4
4
  Domain,
@@ -18,6 +18,7 @@ import {
18
18
  getInitialPmGrade,
19
19
  getTreeGrades,
20
20
  isTreeDataReady,
21
+ isTreeDataWithoutGradeReady,
21
22
  } from '../shared/pmProgress.helpers'
22
23
  import { TreeNormalizer } from '../shared/TreeNormalizer'
23
24
  import { persist } from 'effector-storage/session'
@@ -30,12 +31,14 @@ export class PmTreeModel {
30
31
  private readonly $user = createStore<User | null>(null)
31
32
 
32
33
  private readonly setupInitialGrade = createEvent<SetupInitialGradeProps>()
33
- private readonly setDomains = createEvent<Domain[]>()
34
34
  public readonly setGrade = createEvent<number | null>()
35
35
 
36
36
  public readonly $isInitialized = createStore(false)
37
37
  public readonly $grade = restore(this.setGrade, null)
38
- public readonly $domains = restore(this.setDomains, [])
38
+ public readonly $domains = createStore<Record<number, Domain[]>>({})
39
+ public readonly $domainsInGrade = combine(this.$domains, this.$grade, (domains, grade) =>
40
+ grade !== null ? (domains[grade] ?? []) : [],
41
+ )
39
42
  public readonly $grades = createStore<Grade[]>([])
40
43
  public readonly $status = createStore<PmProgressStatus | null>(null)
41
44
 
@@ -48,7 +51,7 @@ export class PmTreeModel {
48
51
  this.setupFailedAndLockedStatus()
49
52
  this.setupTreeInit()
50
53
  this.setupGradeInit()
51
- this.setupDomainStructure()
54
+ this.setupDomainsInTree()
52
55
  }
53
56
 
54
57
  public readonly initTreeFx = createEffect(async ({ user }: PmProgressGateProps) => {
@@ -150,22 +153,28 @@ export class PmTreeModel {
150
153
  })
151
154
  }
152
155
 
153
- private setupDomainStructure() {
156
+ private setupDomainsInTree() {
154
157
  sample({
155
- clock: [this.$grade, this.initTreeFx.doneData],
156
- source: { tree: this.$tree, stats: this.$stats, user: this.$user, grade: this.$grade },
157
- filter: isTreeDataReady,
158
- fn: ({ tree, stats, user, grade }) => {
159
- const [treeWithUserStats] = enhanceProgressMatrixData(
160
- Object.values(tree.treeMapping),
161
- stats,
162
- [{ entityId: user._id, name: user.fullName }],
163
- grade as number,
158
+ clock: this.initTreeFx.doneData,
159
+ source: { tree: this.$tree, stats: this.$stats, user: this.$user },
160
+ filter: isTreeDataWithoutGradeReady,
161
+ fn: ({ tree, stats, user }) => {
162
+ const treeNodes = Object.values(tree.treeMapping)
163
+ const grades = getTreeGrades(tree, user).filter((g) => !g.isLocked)
164
+
165
+ return Object.fromEntries(
166
+ grades.map((grade) => {
167
+ const [treeWithStats] = enhanceProgressMatrixData(
168
+ treeNodes,
169
+ stats,
170
+ [{ entityId: user._id, name: user.fullName }],
171
+ grade.value,
172
+ )
173
+ return [grade.value, getDomainStructure(treeWithStats, tree.treeMapping)]
174
+ }),
164
175
  )
165
-
166
- return getDomainStructure(treeWithUserStats, tree.treeMapping)
167
176
  },
168
- target: this.setDomains,
177
+ target: this.$domains,
169
178
  })
170
179
  }
171
180
  }
@@ -171,6 +171,14 @@ type TreeDataReady = {
171
171
  export const isTreeDataReady = (source: TreeDataSource): source is TreeDataReady =>
172
172
  source.tree !== null && source.stats !== null && source.user !== null && source.grade !== null
173
173
 
174
+ type TreeDataWithoutGrade = Omit<TreeDataSource, 'grade'>
175
+ type TreeDataWithoutGradeReady = Omit<TreeDataReady, 'grade'>
176
+
177
+ export const isTreeDataWithoutGradeReady = (
178
+ source: TreeDataWithoutGrade,
179
+ ): source is TreeDataWithoutGradeReady =>
180
+ source.tree !== null && source.stats !== null && source.user !== null
181
+
174
182
  export const createChartConfig = (size: number): PieChartManagerConfig => {
175
183
  const OUTER_MARGIN = 5
176
184
  return {
@@ -261,6 +269,9 @@ export const withoutDuplicates = (skills: (Skill | undefined)[]): Skill[] => {
261
269
  })
262
270
  }
263
271
 
272
+ export const findDomainBySkillId = (skillId: string, domains: Domain[]): Domain | undefined =>
273
+ domains.find((d) => d.standards.some((s) => s.skillIds.includes(skillId)))
274
+
264
275
  // Reorders grades starting from the given grade, wrapping around. [1,2,3] with start=2 → [2,3,1]
265
276
  export const startGradesFrom = (grades: Grade[], startGrade: number): Grade[] => {
266
277
  const index = grades.findIndex(({ value }) => value === startGrade)