@magmamath/students-features 0.2.0 → 0.2.2

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 (94) hide show
  1. package/dist/commonjs/features/chatbot/components/ChatControls/ChatControls.js +21 -5
  2. package/dist/commonjs/features/chatbot/components/ChatControls/ChatControls.js.map +1 -1
  3. package/dist/commonjs/features/feedback/components/EmptyComment/EmptyComment.js +1 -1
  4. package/dist/commonjs/features/feedback/components/EmptyComment/EmptyComment.js.map +1 -1
  5. package/dist/commonjs/features/feedback/components/TeacherFeedback.js +12 -5
  6. package/dist/commonjs/features/feedback/components/TeacherFeedback.js.map +1 -1
  7. package/dist/commonjs/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.js +63 -15
  8. package/dist/commonjs/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.js.map +1 -1
  9. package/dist/commonjs/features/feedback/components/TeacherFeedbackButton/colorSchemes.js +17 -0
  10. package/dist/commonjs/features/feedback/components/TeacherFeedbackButton/colorSchemes.js.map +1 -1
  11. package/dist/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherComment.js +7 -3
  12. package/dist/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherComment.js.map +1 -1
  13. package/dist/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.js +16 -5
  14. package/dist/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.js.map +1 -1
  15. package/dist/commonjs/features/feedback/components/UnreadMessagesBadge.js +3 -2
  16. package/dist/commonjs/features/feedback/components/UnreadMessagesBadge.js.map +1 -1
  17. package/dist/commonjs/features/feedback/constants.js +17 -1
  18. package/dist/commonjs/features/feedback/constants.js.map +1 -1
  19. package/dist/commonjs/features/feedback/index.js +11 -0
  20. package/dist/commonjs/features/feedback/index.js.map +1 -1
  21. package/dist/commonjs/features/feedback/model/teacherFeedback.model.js +102 -34
  22. package/dist/commonjs/features/feedback/model/teacherFeedback.model.js.map +1 -1
  23. package/dist/module/features/chatbot/components/ChatControls/ChatControls.js +22 -6
  24. package/dist/module/features/chatbot/components/ChatControls/ChatControls.js.map +1 -1
  25. package/dist/module/features/feedback/components/EmptyComment/EmptyComment.js +1 -1
  26. package/dist/module/features/feedback/components/EmptyComment/EmptyComment.js.map +1 -1
  27. package/dist/module/features/feedback/components/TeacherFeedback.js +12 -5
  28. package/dist/module/features/feedback/components/TeacherFeedback.js.map +1 -1
  29. package/dist/module/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.js +63 -15
  30. package/dist/module/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.js.map +1 -1
  31. package/dist/module/features/feedback/components/TeacherFeedbackButton/colorSchemes.js +17 -0
  32. package/dist/module/features/feedback/components/TeacherFeedbackButton/colorSchemes.js.map +1 -1
  33. package/dist/module/features/feedback/components/TeacherFeedbackComments/TeacherComment.js +8 -4
  34. package/dist/module/features/feedback/components/TeacherFeedbackComments/TeacherComment.js.map +1 -1
  35. package/dist/module/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.js +17 -6
  36. package/dist/module/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.js.map +1 -1
  37. package/dist/module/features/feedback/components/UnreadMessagesBadge.js +3 -2
  38. package/dist/module/features/feedback/components/UnreadMessagesBadge.js.map +1 -1
  39. package/dist/module/features/feedback/constants.js +16 -0
  40. package/dist/module/features/feedback/constants.js.map +1 -1
  41. package/dist/module/features/feedback/index.js +1 -0
  42. package/dist/module/features/feedback/index.js.map +1 -1
  43. package/dist/module/features/feedback/model/teacherFeedback.model.js +102 -34
  44. package/dist/module/features/feedback/model/teacherFeedback.model.js.map +1 -1
  45. package/dist/typescript/commonjs/features/chatbot/components/ChatControls/ChatControls.d.ts.map +1 -1
  46. package/dist/typescript/commonjs/features/feedback/components/TeacherFeedback.d.ts +4 -1
  47. package/dist/typescript/commonjs/features/feedback/components/TeacherFeedback.d.ts.map +1 -1
  48. package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.d.ts +4 -1
  49. package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.d.ts.map +1 -1
  50. package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackButton/colorSchemes.d.ts +17 -0
  51. package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackButton/colorSchemes.d.ts.map +1 -1
  52. package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherComment.d.ts +2 -1
  53. package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherComment.d.ts.map +1 -1
  54. package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.d.ts +3 -1
  55. package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.d.ts.map +1 -1
  56. package/dist/typescript/commonjs/features/feedback/components/UnreadMessagesBadge.d.ts +3 -2
  57. package/dist/typescript/commonjs/features/feedback/components/UnreadMessagesBadge.d.ts.map +1 -1
  58. package/dist/typescript/commonjs/features/feedback/constants.d.ts +13 -0
  59. package/dist/typescript/commonjs/features/feedback/constants.d.ts.map +1 -1
  60. package/dist/typescript/commonjs/features/feedback/index.d.ts +1 -0
  61. package/dist/typescript/commonjs/features/feedback/index.d.ts.map +1 -1
  62. package/dist/typescript/commonjs/features/feedback/model/teacherFeedback.model.d.ts +11 -4
  63. package/dist/typescript/commonjs/features/feedback/model/teacherFeedback.model.d.ts.map +1 -1
  64. package/dist/typescript/module/features/chatbot/components/ChatControls/ChatControls.d.ts.map +1 -1
  65. package/dist/typescript/module/features/feedback/components/TeacherFeedback.d.ts +4 -1
  66. package/dist/typescript/module/features/feedback/components/TeacherFeedback.d.ts.map +1 -1
  67. package/dist/typescript/module/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.d.ts +4 -1
  68. package/dist/typescript/module/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.d.ts.map +1 -1
  69. package/dist/typescript/module/features/feedback/components/TeacherFeedbackButton/colorSchemes.d.ts +17 -0
  70. package/dist/typescript/module/features/feedback/components/TeacherFeedbackButton/colorSchemes.d.ts.map +1 -1
  71. package/dist/typescript/module/features/feedback/components/TeacherFeedbackComments/TeacherComment.d.ts +2 -1
  72. package/dist/typescript/module/features/feedback/components/TeacherFeedbackComments/TeacherComment.d.ts.map +1 -1
  73. package/dist/typescript/module/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.d.ts +3 -1
  74. package/dist/typescript/module/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.d.ts.map +1 -1
  75. package/dist/typescript/module/features/feedback/components/UnreadMessagesBadge.d.ts +3 -2
  76. package/dist/typescript/module/features/feedback/components/UnreadMessagesBadge.d.ts.map +1 -1
  77. package/dist/typescript/module/features/feedback/constants.d.ts +13 -0
  78. package/dist/typescript/module/features/feedback/constants.d.ts.map +1 -1
  79. package/dist/typescript/module/features/feedback/index.d.ts +1 -0
  80. package/dist/typescript/module/features/feedback/index.d.ts.map +1 -1
  81. package/dist/typescript/module/features/feedback/model/teacherFeedback.model.d.ts +11 -4
  82. package/dist/typescript/module/features/feedback/model/teacherFeedback.model.d.ts.map +1 -1
  83. package/package.json +4 -4
  84. package/src/features/chatbot/components/ChatControls/ChatControls.tsx +27 -4
  85. package/src/features/feedback/components/EmptyComment/EmptyComment.tsx +1 -1
  86. package/src/features/feedback/components/TeacherFeedback.tsx +10 -4
  87. package/src/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.tsx +88 -16
  88. package/src/features/feedback/components/TeacherFeedbackButton/colorSchemes.ts +17 -0
  89. package/src/features/feedback/components/TeacherFeedbackComments/TeacherComment.tsx +6 -5
  90. package/src/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.tsx +24 -4
  91. package/src/features/feedback/components/UnreadMessagesBadge.tsx +4 -3
  92. package/src/features/feedback/constants.ts +17 -0
  93. package/src/features/feedback/index.ts +1 -0
  94. package/src/features/feedback/model/teacherFeedback.model.ts +109 -36
@@ -1,5 +1,5 @@
1
1
  import React from 'react'
2
- import { View, Text, StyleSheet, Platform } from 'react-native'
2
+ import { View, Text, StyleSheet } from 'react-native'
3
3
  import { COLORS } from '@magmamath/react-native-ui'
4
4
  import { getRelativeTime } from '../../helpers'
5
5
  import { BUENOS_AIRES_FONT } from '../../constants'
@@ -10,11 +10,12 @@ type TeacherCommentProps = {
10
10
  teacherName: string
11
11
  createdAt: Date
12
12
  locale: Locale | null
13
+ isLastComment: boolean
13
14
  }
14
15
 
15
- export const TeacherComment = ({ content, teacherName, createdAt, locale }: TeacherCommentProps) => {
16
+ export const TeacherComment = ({ content, teacherName, createdAt, locale, isLastComment }: TeacherCommentProps) => {
16
17
  return (
17
- <>
18
+ <View style={{ marginBottom: isLastComment ? 8 : 0 }}>
18
19
  <View style={styles.authorInfo}>
19
20
  <Text style={styles.teacherName} numberOfLines={1}>
20
21
  {teacherName}
@@ -28,7 +29,7 @@ export const TeacherComment = ({ content, teacherName, createdAt, locale }: Teac
28
29
  <View style={styles.container}>
29
30
  <Text style={styles.text}>{content}</Text>
30
31
  </View>
31
- </>
32
+ </View>
32
33
  )
33
34
  }
34
35
 
@@ -39,7 +40,7 @@ const styles = StyleSheet.create({
39
40
  borderTopLeftRadius: 8,
40
41
  borderTopRightRadius: 8,
41
42
  borderBottomRightRadius: 8,
42
- shadowColor: COLORS.PRIMARY_SHADOW,
43
+ shadowColor: COLORS.NEUTRAL_10,
43
44
  shadowOffset: { width: 0, height: 1 },
44
45
  shadowOpacity: 0.25,
45
46
  shadowRadius: 3,
@@ -3,20 +3,28 @@ import { Platform, ScrollView, StyleSheet, useWindowDimensions, View } from 'rea
3
3
  import { Locale, TeacherComment as FeedbackComment } from '../../types/teacherFeedback.types'
4
4
  import { TeacherComment } from './TeacherComment'
5
5
  import { EmptyComment } from '../EmptyComment/EmptyComment'
6
- import { EMPTY_COMMENT_ID } from '../../constants'
6
+ import { EMPTY_COMMENT_ID, FeedbackMode } from '../../constants'
7
+ import { COLORS } from '@magmamath/react-native-ui'
7
8
 
8
9
  const TOOLBAR_HEIGHT = 140
9
10
  const BOTTOM_OFFSET = Platform.OS === 'web' ? 270 : 304
11
+ const SIMPLE_MODE_OFFSET = 70
10
12
 
11
13
  type TeacherFeedbackCommentsProps = {
12
14
  comments: FeedbackComment[] | null
13
15
  locale: Locale | null
16
+ mode: FeedbackMode
14
17
  }
15
18
 
16
- export const TeacherFeedbackComments = ({ comments, locale }: TeacherFeedbackCommentsProps) => {
19
+ export const TeacherFeedbackComments = ({
20
+ comments,
21
+ locale,
22
+ mode,
23
+ }: TeacherFeedbackCommentsProps) => {
17
24
  const ref = useRef<ScrollView | null>(null)
18
25
  const dimensions = useWindowDimensions()
19
26
  const MAX_HEIGHT = dimensions.height - TOOLBAR_HEIGHT - BOTTOM_OFFSET
27
+ const isSimpleMode = mode === FeedbackMode.SIMPLE
20
28
 
21
29
  useEffect(() => {
22
30
  ref.current?.scrollToEnd({ animated: false })
@@ -25,7 +33,12 @@ export const TeacherFeedbackComments = ({ comments, locale }: TeacherFeedbackCom
25
33
  if (!comments) return null
26
34
 
27
35
  return (
28
- <View style={[styles.container, { maxHeight: MAX_HEIGHT }]}>
36
+ <View
37
+ style={[
38
+ styles.container,
39
+ { maxHeight: MAX_HEIGHT - (isSimpleMode ? SIMPLE_MODE_OFFSET : 0) },
40
+ ]}
41
+ >
29
42
  <ScrollView
30
43
  ref={ref}
31
44
  contentContainerStyle={styles.commentsList}
@@ -34,13 +47,14 @@ export const TeacherFeedbackComments = ({ comments, locale }: TeacherFeedbackCom
34
47
  {comments.length === 1 && comments[0]._id === EMPTY_COMMENT_ID ? (
35
48
  <EmptyComment locale={locale} />
36
49
  ) : (
37
- comments.map((comment) => (
50
+ comments.map((comment, index) => (
38
51
  <TeacherComment
39
52
  key={comment._id}
40
53
  teacherName={comment.teacherName}
41
54
  content={comment.content}
42
55
  createdAt={comment.createdAt}
43
56
  locale={locale}
57
+ isLastComment={index === comments.length - 1}
44
58
  />
45
59
  ))
46
60
  )}
@@ -52,6 +66,12 @@ export const TeacherFeedbackComments = ({ comments, locale }: TeacherFeedbackCom
52
66
  const styles = StyleSheet.create({
53
67
  container: {
54
68
  width: 368,
69
+ backgroundColor: COLORS.NEUTRAL_1,
70
+ paddingTop: 8,
71
+ paddingLeft: 8,
72
+ paddingRight: 8,
73
+ paddingBottom: 0,
74
+ borderRadius: 8,
55
75
  },
56
76
  commentsList: {
57
77
  gap: 8,
@@ -1,14 +1,15 @@
1
1
  import React from 'react'
2
- import { Text, View, StyleSheet, Platform, StyleProp, ViewStyle } from 'react-native'
2
+ import { Text, View, StyleSheet, Platform, StyleProp, ViewStyle, TextStyle } from 'react-native'
3
3
  import { COLORS } from '@magmamath/react-native-ui'
4
4
 
5
5
  type UnreadMessagesBadgeProps = {
6
6
  badgeContent?: number
7
7
  withBorder?: boolean
8
8
  style?: StyleProp<ViewStyle>
9
+ textStyle?: StyleProp<TextStyle>
9
10
  }
10
11
 
11
- export const UnreadMessagesBadge = ({ badgeContent, withBorder = false, style }: UnreadMessagesBadgeProps) => {
12
+ export const UnreadMessagesBadge = ({ badgeContent, withBorder = false, style, textStyle }: UnreadMessagesBadgeProps) => {
12
13
  return (
13
14
  <View
14
15
  style={[
@@ -19,7 +20,7 @@ export const UnreadMessagesBadge = ({ badgeContent, withBorder = false, style }:
19
20
  withBorder && (badgeContent ? styles.withBorderSize : styles.withBorderSizeEmpty),
20
21
  ]}
21
22
  >
22
- <Text style={styles.text}>{badgeContent && badgeContent > 99 ? '99+' : badgeContent}</Text>
23
+ <Text style={[styles.text, textStyle]}>{badgeContent && badgeContent > 99 ? '99+' : badgeContent}</Text>
23
24
  </View>
24
25
  )
25
26
  }
@@ -22,3 +22,20 @@ export const getEmptyComment = (problemId: string, locale: Locale | null) => {
22
22
  updatedAt: new Date(),
23
23
  }
24
24
  }
25
+
26
+ export const TEACHER_FEEDBACK_BUTTON_ID = 'teacherFeedbackButton'
27
+
28
+ export enum FeedbackButtonColors {
29
+ BLUE = 'BLUE',
30
+ PURPLE = 'PURPLE',
31
+ }
32
+
33
+ export enum FeedbackButtonSize {
34
+ SMALL = 'SMALL',
35
+ LARGE = 'LARGE',
36
+ }
37
+
38
+ export enum FeedbackMode {
39
+ SIMPLE = 'SIMPLE',
40
+ NORMAL = 'NORMAL',
41
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './model/teacherFeedback.model'
2
2
  export * from './types/teacherFeedback.types'
3
+ export * from './constants'
3
4
  export * from './components'
@@ -10,6 +10,7 @@ import { EMPTY_COMMENT_ID, getEmptyComment } from '../constants'
10
10
 
11
11
  type TeacherFeedbackModelProps = {
12
12
  credits: {
13
+ assignmentId: StoreWritable<string>
13
14
  problemId: StoreWritable<string>
14
15
  locale: StoreWritable<Locale | null>
15
16
  }
@@ -19,19 +20,28 @@ type TeacherFeedbackModelProps = {
19
20
  }
20
21
  }
21
22
 
23
+ type CommentsMap = Map<string, Record<string, CommentsEntity>>
24
+
22
25
  export class TeacherFeedbackModel {
26
+ $assignmentId: StoreWritable<string>
23
27
  $currentProblemId: StoreWritable<string>
24
28
  $locale: StoreWritable<Locale | null>
25
29
 
26
- setCommentsSeen = createEvent<{ ids: string[]; currentProblemId: string }>()
27
- $comments = createStore<Map<string, CommentsEntity>>(new Map())
30
+ setCommentsSeen = createEvent<{ ids: string[]; currentProblemId: string; assignmentId: string }>()
31
+ $comments = createStore<CommentsMap>(new Map())
28
32
 
29
33
  setIsOpened = createEvent<boolean>()
30
34
  $isOpened = restore(this.setIsOpened, false)
31
35
  setIsVisible = createEvent<boolean>()
32
36
  $isVisible = restore(this.setIsVisible, false)
33
37
 
34
- getCommentsByAssignmentIdFx: Effect<GetCommentsByIdProps, Record<string, { comments: TeacherComment[] }>>
38
+ getCommentsByAssignmentIdFx: Effect<
39
+ GetCommentsByIdProps,
40
+ {
41
+ data: Record<string, { comments: TeacherComment[] }>
42
+ assignmentId: string
43
+ }
44
+ >
35
45
  updateCommentSeenFx: Effect<UpdateCommentSeenStatusProps, void>
36
46
 
37
47
  sockets = {
@@ -40,8 +50,15 @@ export class TeacherFeedbackModel {
40
50
  }
41
51
 
42
52
  constructor({ api, credits }: TeacherFeedbackModelProps) {
43
- this.getCommentsByAssignmentIdFx = createEffect(api.getCommentsByAssignmentId)
53
+ this.getCommentsByAssignmentIdFx = createEffect(async ({ id }: { id: string }) => {
54
+ const response = await api.getCommentsByAssignmentId({ id })
55
+ return {
56
+ data: response,
57
+ assignmentId: id,
58
+ }
59
+ })
44
60
  this.updateCommentSeenFx = createEffect(api.updateCommentSeenStatus)
61
+ this.$assignmentId = credits.assignmentId
45
62
  this.$currentProblemId = credits.problemId
46
63
  this.$locale = credits.locale
47
64
 
@@ -53,10 +70,13 @@ export class TeacherFeedbackModel {
53
70
 
54
71
  sample({
55
72
  clock: this.sockets.onCreate,
56
- source: [this.$isOpened, this.$currentProblemId] as const,
57
- filter: ([isOpen]) => isOpen,
58
- fn: ([_, currentProblemId], { _id }) => ({
73
+ source: [this.$isOpened, this.$currentProblemId, this.$assignmentId] as const,
74
+ filter: ([isOpen, currentProblemId], payload) => {
75
+ return isOpen && currentProblemId === payload.problemId
76
+ },
77
+ fn: ([_, currentProblemId, assignmentId], { _id }) => ({
59
78
  currentProblemId,
79
+ assignmentId,
60
80
  ids: [_id],
61
81
  }),
62
82
  target: [this.setCommentsSeen, this.updateCommentSeenFx],
@@ -64,42 +84,50 @@ export class TeacherFeedbackModel {
64
84
 
65
85
  sample({
66
86
  clock: this.$isOpened,
67
- source: [this.$comments, this.$currentProblemId] as const,
68
- filter: ([feedback, currentProblemId], isOpen) => {
69
- const comments = feedback.get(currentProblemId)?.comments ?? []
87
+ source: [this.$comments, this.$currentProblemId, this.$assignmentId] as const,
88
+ filter: ([feedback, currentProblemId, assignmentId], isOpen) => {
89
+ const assignmentComments = feedback.get(assignmentId) || {}
90
+ const comments = assignmentComments[currentProblemId]?.comments ?? []
70
91
  const hasUnreadComments = comments.some((comment) => !comment.isRead)
71
92
  return isOpen && hasUnreadComments
72
93
  },
73
- fn: ([feedback, currentProblemId]) => {
74
- const comments = feedback.get(currentProblemId)?.comments ?? []
94
+ fn: ([feedback, currentProblemId, assignmentId]) => {
95
+ const assignmentComments = feedback.get(assignmentId) || {}
96
+ const comments = assignmentComments[currentProblemId]?.comments ?? []
75
97
  return {
76
98
  currentProblemId,
99
+ assignmentId,
77
100
  ids: comments.filter((comment) => !comment.isRead).map((comment) => comment._id),
78
101
  }
79
102
  },
80
103
  target: [this.setCommentsSeen, this.updateCommentSeenFx],
81
104
  })
82
105
 
83
- this.$isVisible.on(this.getCommentsByAssignmentIdFx.doneData, (_, payload) => {
84
- return Object.values(payload).some((problemFeedback) => problemFeedback.comments?.length > 0)
106
+ this.$isVisible.on(this.getCommentsByAssignmentIdFx.doneData, (_, { data }) => {
107
+ return Object.values(data).some((problemFeedback) => problemFeedback.comments?.length > 0)
85
108
  })
86
109
 
87
110
  this.$comments
88
- .on(this.getCommentsByAssignmentIdFx.doneData, (_, payload) => {
89
- const state = new Map()
111
+ .on(this.getCommentsByAssignmentIdFx.doneData, (state, { assignmentId, data }) => {
112
+ const problemsMap: Record<string, CommentsEntity> = {}
90
113
 
91
- for (const [problemId, { comments }] of Object.entries(payload)) {
114
+ for (const [problemId, { comments }] of Object.entries(data)) {
92
115
  const unreadMessages = comments.filter((comment) => !comment.isRead)
93
- state.set(problemId, {
116
+ problemsMap[problemId] = {
94
117
  comments,
95
118
  unreadMessagesCount: unreadMessages.length,
96
- })
119
+ }
97
120
  }
98
121
 
99
- return state
122
+ const updatedState = new Map(state)
123
+ updatedState.set(assignmentId, problemsMap)
124
+ return updatedState
100
125
  })
101
- .on(this.setCommentsSeen, (state, { ids, currentProblemId }) => {
102
- const feedback = state.get(currentProblemId)
126
+ .on(this.setCommentsSeen, (state, { ids, currentProblemId, assignmentId }) => {
127
+ const assignmentComments = state.get(assignmentId)
128
+ if (!assignmentComments) return state
129
+
130
+ const feedback = assignmentComments[currentProblemId]
103
131
  if (!feedback) return state
104
132
 
105
133
  const updatedComments = feedback.comments.map((comment) =>
@@ -112,13 +140,19 @@ export class TeacherFeedbackModel {
112
140
  unreadMessagesCount: 0,
113
141
  }
114
142
 
143
+ const updatedAssignmentComments = {
144
+ ...assignmentComments,
145
+ [currentProblemId]: updatedFeedback,
146
+ }
147
+
115
148
  const updatedState = new Map(state)
116
- updatedState.set(currentProblemId, updatedFeedback)
149
+ updatedState.set(assignmentId, updatedAssignmentComments)
117
150
 
118
151
  return updatedState
119
152
  })
120
153
  .on(this.sockets.onCreate, (state, payload) => {
121
- const feedback = state.get(payload.problemId) ?? { comments: [], unreadMessagesCount: 0 }
154
+ const assignmentComments = state.get(payload.exerciseId) || {}
155
+ const feedback = assignmentComments[payload.problemId] ?? { comments: [], unreadMessagesCount: 0 }
122
156
 
123
157
  const updatedFeedback = {
124
158
  ...feedback,
@@ -126,13 +160,22 @@ export class TeacherFeedbackModel {
126
160
  unreadMessagesCount: feedback.unreadMessagesCount + 1,
127
161
  }
128
162
 
163
+ const updatedAssignmentComments = {
164
+ ...assignmentComments,
165
+ [payload.problemId]: updatedFeedback,
166
+ }
167
+
129
168
  const updatedState = new Map(state)
130
- updatedState.set(payload.problemId, updatedFeedback)
169
+ updatedState.set(payload.exerciseId, updatedAssignmentComments)
131
170
 
132
171
  return updatedState
133
172
  })
134
173
  .on(this.sockets.onDeleted, (state, payload) => {
135
- const feedback = state.get(payload.problemId)
174
+ const assignmentId = this.$assignmentId.getState()
175
+ const assignmentComments = state.get(assignmentId)
176
+ if (!assignmentComments) return state
177
+
178
+ const feedback = assignmentComments[payload.problemId]
136
179
  if (!feedback) return state
137
180
 
138
181
  const isDeleteMessageUnread = feedback.comments.some(
@@ -144,35 +187,65 @@ export class TeacherFeedbackModel {
144
187
  unreadMessagesCount: isDeleteMessageUnread ? feedback.unreadMessagesCount - 1 : feedback.unreadMessagesCount,
145
188
  }
146
189
 
147
- const updatedState = new Map(state)
148
190
  const isOpen = this.$isOpened.getState()
149
191
 
150
192
  if (updatedFeedback.comments.length === 0) {
193
+ const updatedAssignmentComments = { ...assignmentComments }
194
+
151
195
  if (!isOpen) {
152
- updatedState.delete(payload.problemId)
153
- return updatedState
196
+ delete updatedAssignmentComments[payload.problemId]
197
+
198
+ // If no problems left, remove the assignment entirely
199
+ if (Object.keys(updatedAssignmentComments).length === 0) {
200
+ const updatedState = new Map(state)
201
+ updatedState.delete(assignmentId)
202
+ return updatedState
203
+ }
204
+ } else {
205
+ updatedAssignmentComments[payload.problemId] = {
206
+ ...updatedFeedback,
207
+ comments: [getEmptyComment(payload.problemId, this.$locale.getState())],
208
+ }
154
209
  }
155
210
 
156
- const feedbackWithCustomMessage = { ...updatedFeedback }
157
- feedbackWithCustomMessage.comments = [getEmptyComment(payload.problemId, this.$locale.getState())]
158
- updatedState.set(payload.problemId, feedbackWithCustomMessage)
159
-
211
+ const updatedState = new Map(state)
212
+ updatedState.set(assignmentId, updatedAssignmentComments)
160
213
  return updatedState
161
214
  }
162
215
 
163
- updatedState.set(payload.problemId, updatedFeedback)
216
+ const updatedAssignmentComments = {
217
+ ...assignmentComments,
218
+ [payload.problemId]: updatedFeedback,
219
+ }
220
+
221
+ const updatedState = new Map(state)
222
+ updatedState.set(assignmentId, updatedAssignmentComments)
164
223
  return updatedState
165
224
  })
166
225
  .on(this.setIsOpened, (state, isOpen) => {
167
226
  if (isOpen) return state
168
227
 
228
+ const assignmentId = this.$assignmentId.getState()
169
229
  const problemId = this.$currentProblemId.getState()
170
- const feedback = state.get(problemId)
230
+ const assignmentComments = state.get(assignmentId)
231
+ if (!assignmentComments) return state
232
+
233
+ const feedback = assignmentComments[problemId]
171
234
  if (!feedback) return state
172
235
 
173
236
  if (feedback.comments.length === 1 && feedback.comments[0]._id === EMPTY_COMMENT_ID) {
237
+ const updatedAssignmentComments = { ...assignmentComments }
238
+ delete updatedAssignmentComments[problemId]
239
+
240
+ // If no problems left, remove the assignment entirely
241
+ if (Object.keys(updatedAssignmentComments).length === 0) {
242
+ const updatedState = new Map(state)
243
+ updatedState.delete(assignmentId)
244
+ return updatedState
245
+ }
246
+
174
247
  const updatedState = new Map(state)
175
- updatedState.delete(problemId)
248
+ updatedState.set(assignmentId, updatedAssignmentComments)
176
249
  return updatedState
177
250
  }
178
251