@magmamath/students-features 0.2.0-hotfix-circular-dependencies-chatbot → 0.2.0
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.
- package/dist/commonjs/features/chatbot/components/ChatControls/ChatControls.js +5 -21
- package/dist/commonjs/features/chatbot/components/ChatControls/ChatControls.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/model.js +2 -12
- package/dist/commonjs/features/chatbot/model/model.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/t2s.js +4 -8
- package/dist/commonjs/features/chatbot/model/t2s.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/translation.js +15 -30
- package/dist/commonjs/features/chatbot/model/translation.js.map +1 -1
- package/dist/commonjs/features/feedback/components/EmptyComment/EmptyComment.js +3 -2
- package/dist/commonjs/features/feedback/components/EmptyComment/EmptyComment.js.map +1 -1
- package/dist/commonjs/features/feedback/components/TeacherFeedback.js +5 -9
- package/dist/commonjs/features/feedback/components/TeacherFeedback.js.map +1 -1
- package/dist/commonjs/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.js +11 -47
- package/dist/commonjs/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.js.map +1 -1
- package/dist/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherComment.js +3 -7
- package/dist/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherComment.js.map +1 -1
- package/dist/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.js +5 -15
- package/dist/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.js.map +1 -1
- package/dist/commonjs/features/feedback/components/UnreadMessagesBadge.js +3 -6
- package/dist/commonjs/features/feedback/components/UnreadMessagesBadge.js.map +1 -1
- package/dist/commonjs/features/feedback/constants.js +1 -2
- package/dist/commonjs/features/feedback/constants.js.map +1 -1
- package/dist/commonjs/features/feedback/index.js +0 -11
- package/dist/commonjs/features/feedback/index.js.map +1 -1
- package/dist/commonjs/features/feedback/model/teacherFeedback.model.js +34 -102
- package/dist/commonjs/features/feedback/model/teacherFeedback.model.js.map +1 -1
- package/dist/module/features/chatbot/components/ChatControls/ChatControls.js +6 -22
- package/dist/module/features/chatbot/components/ChatControls/ChatControls.js.map +1 -1
- package/dist/module/features/chatbot/model/model.js +2 -12
- package/dist/module/features/chatbot/model/model.js.map +1 -1
- package/dist/module/features/chatbot/model/t2s.js +4 -8
- package/dist/module/features/chatbot/model/t2s.js.map +1 -1
- package/dist/module/features/chatbot/model/translation.js +15 -30
- package/dist/module/features/chatbot/model/translation.js.map +1 -1
- package/dist/module/features/feedback/components/EmptyComment/EmptyComment.js +3 -2
- package/dist/module/features/feedback/components/EmptyComment/EmptyComment.js.map +1 -1
- package/dist/module/features/feedback/components/TeacherFeedback.js +5 -9
- package/dist/module/features/feedback/components/TeacherFeedback.js.map +1 -1
- package/dist/module/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.js +11 -47
- package/dist/module/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.js.map +1 -1
- package/dist/module/features/feedback/components/TeacherFeedbackComments/TeacherComment.js +4 -8
- package/dist/module/features/feedback/components/TeacherFeedbackComments/TeacherComment.js.map +1 -1
- package/dist/module/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.js +5 -15
- package/dist/module/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.js.map +1 -1
- package/dist/module/features/feedback/components/UnreadMessagesBadge.js +3 -6
- package/dist/module/features/feedback/components/UnreadMessagesBadge.js.map +1 -1
- package/dist/module/features/feedback/constants.js +0 -1
- package/dist/module/features/feedback/constants.js.map +1 -1
- package/dist/module/features/feedback/index.js +0 -1
- package/dist/module/features/feedback/index.js.map +1 -1
- package/dist/module/features/feedback/model/teacherFeedback.model.js +34 -102
- package/dist/module/features/feedback/model/teacherFeedback.model.js.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/components/ChatControls/ChatControls.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/model.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/t2s.d.ts +5 -7
- package/dist/typescript/commonjs/features/chatbot/model/t2s.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/translation.d.ts +5 -10
- package/dist/typescript/commonjs/features/chatbot/model/translation.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/feedback/components/TeacherFeedback.d.ts +1 -2
- package/dist/typescript/commonjs/features/feedback/components/TeacherFeedback.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.d.ts +1 -2
- package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherComment.d.ts +1 -2
- package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherComment.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.d.ts +1 -2
- package/dist/typescript/commonjs/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/feedback/components/UnreadMessagesBadge.d.ts +2 -3
- package/dist/typescript/commonjs/features/feedback/components/UnreadMessagesBadge.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/feedback/constants.d.ts +0 -1
- package/dist/typescript/commonjs/features/feedback/constants.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/feedback/index.d.ts +0 -1
- package/dist/typescript/commonjs/features/feedback/index.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/feedback/model/teacherFeedback.model.d.ts +4 -11
- package/dist/typescript/commonjs/features/feedback/model/teacherFeedback.model.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/components/ChatControls/ChatControls.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/model.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/t2s.d.ts +5 -7
- package/dist/typescript/module/features/chatbot/model/t2s.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/translation.d.ts +5 -10
- package/dist/typescript/module/features/chatbot/model/translation.d.ts.map +1 -1
- package/dist/typescript/module/features/feedback/components/TeacherFeedback.d.ts +1 -2
- package/dist/typescript/module/features/feedback/components/TeacherFeedback.d.ts.map +1 -1
- package/dist/typescript/module/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.d.ts +1 -2
- package/dist/typescript/module/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.d.ts.map +1 -1
- package/dist/typescript/module/features/feedback/components/TeacherFeedbackComments/TeacherComment.d.ts +1 -2
- package/dist/typescript/module/features/feedback/components/TeacherFeedbackComments/TeacherComment.d.ts.map +1 -1
- package/dist/typescript/module/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.d.ts +1 -2
- package/dist/typescript/module/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.d.ts.map +1 -1
- package/dist/typescript/module/features/feedback/components/UnreadMessagesBadge.d.ts +2 -3
- package/dist/typescript/module/features/feedback/components/UnreadMessagesBadge.d.ts.map +1 -1
- package/dist/typescript/module/features/feedback/constants.d.ts +0 -1
- package/dist/typescript/module/features/feedback/constants.d.ts.map +1 -1
- package/dist/typescript/module/features/feedback/index.d.ts +0 -1
- package/dist/typescript/module/features/feedback/index.d.ts.map +1 -1
- package/dist/typescript/module/features/feedback/model/teacherFeedback.model.d.ts +4 -11
- package/dist/typescript/module/features/feedback/model/teacherFeedback.model.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/features/chatbot/components/ChatControls/ChatControls.tsx +4 -27
- package/src/features/chatbot/model/model.ts +2 -13
- package/src/features/chatbot/model/t2s.ts +7 -13
- package/src/features/chatbot/model/translation.ts +27 -46
- package/src/features/feedback/components/EmptyComment/EmptyComment.tsx +2 -1
- package/src/features/feedback/components/TeacherFeedback.tsx +4 -7
- package/src/features/feedback/components/TeacherFeedbackButton/TeacherFeedbackButton.tsx +10 -48
- package/src/features/feedback/components/TeacherFeedbackComments/TeacherComment.tsx +5 -6
- package/src/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.tsx +3 -13
- package/src/features/feedback/components/UnreadMessagesBadge.tsx +4 -7
- package/src/features/feedback/constants.ts +0 -2
- package/src/features/feedback/index.ts +0 -1
- package/src/features/feedback/model/teacherFeedback.model.ts +36 -109
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { StyleSheet, View } from 'react-native'
|
|
3
3
|
import { Button, COLORS } from '@magmamath/react-native-ui'
|
|
4
4
|
import { UnreadMessagesBadge } from '../UnreadMessagesBadge'
|
|
5
5
|
import { MessageBubbleIcon } from '../icons/MessageBubbleIcon'
|
|
6
6
|
import { XCloseIcon } from '../icons/XCloseIcon'
|
|
7
7
|
import { COLOR_SCHEMES } from './colorSchemes'
|
|
8
|
-
import { TEACHER_FEEDBACK_BUTTON_ID } from '../../constants'
|
|
9
8
|
|
|
10
9
|
type TeacherFeedbackButtonProps = {
|
|
11
10
|
isOpen: boolean
|
|
12
11
|
isLoading: boolean
|
|
13
12
|
onPress?: () => void
|
|
14
13
|
unreadCommentsCount?: number
|
|
15
|
-
size?: 'small' | 'large'
|
|
16
14
|
}
|
|
17
15
|
|
|
18
16
|
export const TeacherFeedbackButton = ({
|
|
@@ -20,30 +18,22 @@ export const TeacherFeedbackButton = ({
|
|
|
20
18
|
onPress,
|
|
21
19
|
unreadCommentsCount,
|
|
22
20
|
isLoading,
|
|
23
|
-
size = 'large',
|
|
24
21
|
}: TeacherFeedbackButtonProps) => {
|
|
25
|
-
const handlePress = (event: GestureResponderEvent) => {
|
|
26
|
-
event.stopPropagation()
|
|
27
|
-
onPress?.()
|
|
28
|
-
}
|
|
29
|
-
|
|
30
22
|
if (isOpen) {
|
|
31
23
|
return (
|
|
32
24
|
<Button
|
|
33
25
|
key='open'
|
|
34
|
-
|
|
35
|
-
onPress={handlePress}
|
|
26
|
+
onPress={onPress}
|
|
36
27
|
size='large'
|
|
37
28
|
variant='primary'
|
|
38
29
|
disabled={isLoading}
|
|
39
30
|
isLoading={isLoading}
|
|
40
31
|
style={{
|
|
41
32
|
container: styles.container,
|
|
42
|
-
button: [styles.button, { borderColor: COLORS.NEUTRAL_5 }
|
|
33
|
+
button: [styles.button, { borderColor: COLORS.NEUTRAL_5 }],
|
|
43
34
|
}}
|
|
44
|
-
data-skip-confetti='true'
|
|
45
35
|
customColorScheme={COLOR_SCHEMES.GREY}
|
|
46
|
-
icon={<XCloseIcon
|
|
36
|
+
icon={<XCloseIcon />}
|
|
47
37
|
/>
|
|
48
38
|
)
|
|
49
39
|
}
|
|
@@ -51,34 +41,22 @@ export const TeacherFeedbackButton = ({
|
|
|
51
41
|
return (
|
|
52
42
|
<Button
|
|
53
43
|
key='closed'
|
|
54
|
-
|
|
55
|
-
onPress={handlePress}
|
|
44
|
+
onPress={onPress}
|
|
56
45
|
size='large'
|
|
57
46
|
variant='primary'
|
|
58
47
|
disabled={isLoading}
|
|
59
48
|
isLoading={isLoading}
|
|
60
49
|
style={{
|
|
61
50
|
container: styles.container,
|
|
62
|
-
button: [
|
|
63
|
-
styles.button,
|
|
64
|
-
{ borderColor: !!unreadCommentsCount ? COLORS.BLUE_6 : COLORS.NEUTRAL_5 },
|
|
65
|
-
styles[size],
|
|
66
|
-
],
|
|
51
|
+
button: [styles.button, { borderColor: !!unreadCommentsCount ? COLORS.BLUE_6 : COLORS.NEUTRAL_5 }],
|
|
67
52
|
}}
|
|
68
53
|
customColorScheme={!!unreadCommentsCount ? COLOR_SCHEMES.BLUE : COLOR_SCHEMES.GREY}
|
|
69
54
|
icon={
|
|
70
55
|
<View style={styles.iconContainer}>
|
|
71
|
-
<MessageBubbleIcon
|
|
72
|
-
color={!!unreadCommentsCount ? COLORS.NEUTRAL_1 : COLORS.NEUTRAL_9}
|
|
73
|
-
size={size === 'large' ? 37 : 26}
|
|
74
|
-
/>
|
|
56
|
+
<MessageBubbleIcon color={!!unreadCommentsCount ? COLORS.NEUTRAL_1 : COLORS.NEUTRAL_9} />
|
|
75
57
|
{!!unreadCommentsCount && (
|
|
76
|
-
<View style={
|
|
77
|
-
<UnreadMessagesBadge
|
|
78
|
-
badgeContent={unreadCommentsCount}
|
|
79
|
-
textStyle={size === 'large' && { fontSize: 18 }}
|
|
80
|
-
style={size === 'large' && { width: 32, height: 32, borderRadius: 16 }}
|
|
81
|
-
/>
|
|
58
|
+
<View style={styles.badgeContainer}>
|
|
59
|
+
<UnreadMessagesBadge badgeContent={unreadCommentsCount} />
|
|
82
60
|
</View>
|
|
83
61
|
)}
|
|
84
62
|
</View>
|
|
@@ -92,30 +70,14 @@ const styles = StyleSheet.create({
|
|
|
92
70
|
width: 54,
|
|
93
71
|
height: 54,
|
|
94
72
|
},
|
|
95
|
-
|
|
73
|
+
button: {
|
|
96
74
|
width: 50,
|
|
97
75
|
height: 50,
|
|
98
|
-
},
|
|
99
|
-
large: {
|
|
100
|
-
width: 75,
|
|
101
|
-
height: 75,
|
|
102
|
-
},
|
|
103
|
-
button: {
|
|
104
|
-
borderWidth: 2,
|
|
105
|
-
},
|
|
106
|
-
buttonLarge: {
|
|
107
|
-
width: 75,
|
|
108
|
-
height: 75,
|
|
109
76
|
borderWidth: 2,
|
|
110
77
|
},
|
|
111
78
|
iconContainer: {
|
|
112
79
|
position: 'relative',
|
|
113
80
|
},
|
|
114
|
-
badgeContainerLarge: {
|
|
115
|
-
position: 'absolute',
|
|
116
|
-
top: -24,
|
|
117
|
-
right: -24,
|
|
118
|
-
},
|
|
119
81
|
badgeContainer: {
|
|
120
82
|
position: 'absolute',
|
|
121
83
|
top: -17,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { View, Text, StyleSheet } from 'react-native'
|
|
2
|
+
import { View, Text, StyleSheet, Platform } 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,12 +10,11 @@ type TeacherCommentProps = {
|
|
|
10
10
|
teacherName: string
|
|
11
11
|
createdAt: Date
|
|
12
12
|
locale: Locale | null
|
|
13
|
-
isLastComment: boolean
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
export const TeacherComment = ({ content, teacherName, createdAt, locale
|
|
15
|
+
export const TeacherComment = ({ content, teacherName, createdAt, locale }: TeacherCommentProps) => {
|
|
17
16
|
return (
|
|
18
|
-
|
|
17
|
+
<>
|
|
19
18
|
<View style={styles.authorInfo}>
|
|
20
19
|
<Text style={styles.teacherName} numberOfLines={1}>
|
|
21
20
|
{teacherName}
|
|
@@ -29,7 +28,7 @@ export const TeacherComment = ({ content, teacherName, createdAt, locale, isLast
|
|
|
29
28
|
<View style={styles.container}>
|
|
30
29
|
<Text style={styles.text}>{content}</Text>
|
|
31
30
|
</View>
|
|
32
|
-
|
|
31
|
+
</>
|
|
33
32
|
)
|
|
34
33
|
}
|
|
35
34
|
|
|
@@ -40,7 +39,7 @@ const styles = StyleSheet.create({
|
|
|
40
39
|
borderTopLeftRadius: 8,
|
|
41
40
|
borderTopRightRadius: 8,
|
|
42
41
|
borderBottomRightRadius: 8,
|
|
43
|
-
shadowColor: COLORS.
|
|
42
|
+
shadowColor: COLORS.PRIMARY_SHADOW,
|
|
44
43
|
shadowOffset: { width: 0, height: 1 },
|
|
45
44
|
shadowOpacity: 0.25,
|
|
46
45
|
shadowRadius: 3,
|
package/src/features/feedback/components/TeacherFeedbackComments/TeacherFeedbackComments.tsx
CHANGED
|
@@ -4,19 +4,16 @@ import { Locale, TeacherComment as FeedbackComment } from '../../types/teacherFe
|
|
|
4
4
|
import { TeacherComment } from './TeacherComment'
|
|
5
5
|
import { EmptyComment } from '../EmptyComment/EmptyComment'
|
|
6
6
|
import { EMPTY_COMMENT_ID } from '../../constants'
|
|
7
|
-
import { COLORS } from '@magmamath/react-native-ui'
|
|
8
7
|
|
|
9
8
|
const TOOLBAR_HEIGHT = 140
|
|
10
9
|
const BOTTOM_OFFSET = Platform.OS === 'web' ? 270 : 304
|
|
11
|
-
const SIMPLE_MODE_OFFSET = 70
|
|
12
10
|
|
|
13
11
|
type TeacherFeedbackCommentsProps = {
|
|
14
12
|
comments: FeedbackComment[] | null
|
|
15
13
|
locale: Locale | null
|
|
16
|
-
mode: 'regular' | 'simple'
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
export const TeacherFeedbackComments = ({ comments, locale
|
|
16
|
+
export const TeacherFeedbackComments = ({ comments, locale }: TeacherFeedbackCommentsProps) => {
|
|
20
17
|
const ref = useRef<ScrollView | null>(null)
|
|
21
18
|
const dimensions = useWindowDimensions()
|
|
22
19
|
const MAX_HEIGHT = dimensions.height - TOOLBAR_HEIGHT - BOTTOM_OFFSET
|
|
@@ -28,7 +25,7 @@ export const TeacherFeedbackComments = ({ comments, locale, mode }: TeacherFeedb
|
|
|
28
25
|
if (!comments) return null
|
|
29
26
|
|
|
30
27
|
return (
|
|
31
|
-
<View style={[styles.container, { maxHeight: MAX_HEIGHT
|
|
28
|
+
<View style={[styles.container, { maxHeight: MAX_HEIGHT }]}>
|
|
32
29
|
<ScrollView
|
|
33
30
|
ref={ref}
|
|
34
31
|
contentContainerStyle={styles.commentsList}
|
|
@@ -37,14 +34,13 @@ export const TeacherFeedbackComments = ({ comments, locale, mode }: TeacherFeedb
|
|
|
37
34
|
{comments.length === 1 && comments[0]._id === EMPTY_COMMENT_ID ? (
|
|
38
35
|
<EmptyComment locale={locale} />
|
|
39
36
|
) : (
|
|
40
|
-
comments.map((comment
|
|
37
|
+
comments.map((comment) => (
|
|
41
38
|
<TeacherComment
|
|
42
39
|
key={comment._id}
|
|
43
40
|
teacherName={comment.teacherName}
|
|
44
41
|
content={comment.content}
|
|
45
42
|
createdAt={comment.createdAt}
|
|
46
43
|
locale={locale}
|
|
47
|
-
isLastComment={index === comments.length - 1}
|
|
48
44
|
/>
|
|
49
45
|
))
|
|
50
46
|
)}
|
|
@@ -56,12 +52,6 @@ export const TeacherFeedbackComments = ({ comments, locale, mode }: TeacherFeedb
|
|
|
56
52
|
const styles = StyleSheet.create({
|
|
57
53
|
container: {
|
|
58
54
|
width: 368,
|
|
59
|
-
backgroundColor: COLORS.NEUTRAL_1,
|
|
60
|
-
paddingTop: 8,
|
|
61
|
-
paddingLeft: 8,
|
|
62
|
-
paddingRight: 8,
|
|
63
|
-
paddingBottom: 0,
|
|
64
|
-
borderRadius: 8,
|
|
65
55
|
},
|
|
66
56
|
commentsList: {
|
|
67
57
|
gap: 8,
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { Text, View, StyleSheet, Platform, StyleProp, ViewStyle
|
|
2
|
+
import { Text, View, StyleSheet, Platform, StyleProp, ViewStyle } 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>
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
export const UnreadMessagesBadge = ({ badgeContent, withBorder = false, style
|
|
11
|
+
export const UnreadMessagesBadge = ({ badgeContent, withBorder = false, style }: UnreadMessagesBadgeProps) => {
|
|
13
12
|
return (
|
|
14
13
|
<View
|
|
15
14
|
style={[
|
|
@@ -20,7 +19,7 @@ export const UnreadMessagesBadge = ({ badgeContent, withBorder = false, style, t
|
|
|
20
19
|
withBorder && (badgeContent ? styles.withBorderSize : styles.withBorderSizeEmpty),
|
|
21
20
|
]}
|
|
22
21
|
>
|
|
23
|
-
<Text style={
|
|
22
|
+
<Text style={styles.text}>{badgeContent && badgeContent > 99 ? '99+' : badgeContent}</Text>
|
|
24
23
|
</View>
|
|
25
24
|
)
|
|
26
25
|
}
|
|
@@ -53,10 +52,8 @@ const styles = StyleSheet.create({
|
|
|
53
52
|
borderRadius: 5.75,
|
|
54
53
|
},
|
|
55
54
|
text: {
|
|
56
|
-
alignItems: 'center',
|
|
57
|
-
justifyContent: 'center',
|
|
58
55
|
fontSize: 12,
|
|
59
|
-
|
|
56
|
+
lineHeight: 16,
|
|
60
57
|
fontWeight: '600',
|
|
61
58
|
fontFamily: Platform.OS === 'web' ? 'Open Sans, sans-serif' : 'OpenSans-SemiBold',
|
|
62
59
|
color: COLORS.NEUTRAL_1,
|
|
@@ -10,7 +10,6 @@ import { EMPTY_COMMENT_ID, getEmptyComment } from '../constants'
|
|
|
10
10
|
|
|
11
11
|
type TeacherFeedbackModelProps = {
|
|
12
12
|
credits: {
|
|
13
|
-
assignmentId: StoreWritable<string>
|
|
14
13
|
problemId: StoreWritable<string>
|
|
15
14
|
locale: StoreWritable<Locale | null>
|
|
16
15
|
}
|
|
@@ -20,28 +19,19 @@ type TeacherFeedbackModelProps = {
|
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
type CommentsMap = Map<string, Record<string, CommentsEntity>>
|
|
24
|
-
|
|
25
22
|
export class TeacherFeedbackModel {
|
|
26
|
-
$assignmentId: StoreWritable<string>
|
|
27
23
|
$currentProblemId: StoreWritable<string>
|
|
28
24
|
$locale: StoreWritable<Locale | null>
|
|
29
25
|
|
|
30
|
-
setCommentsSeen = createEvent<{ ids: string[]; currentProblemId: string
|
|
31
|
-
$comments = createStore<
|
|
26
|
+
setCommentsSeen = createEvent<{ ids: string[]; currentProblemId: string }>()
|
|
27
|
+
$comments = createStore<Map<string, CommentsEntity>>(new Map())
|
|
32
28
|
|
|
33
29
|
setIsOpened = createEvent<boolean>()
|
|
34
30
|
$isOpened = restore(this.setIsOpened, false)
|
|
35
31
|
setIsVisible = createEvent<boolean>()
|
|
36
32
|
$isVisible = restore(this.setIsVisible, false)
|
|
37
33
|
|
|
38
|
-
getCommentsByAssignmentIdFx: Effect<
|
|
39
|
-
GetCommentsByIdProps,
|
|
40
|
-
{
|
|
41
|
-
data: Record<string, { comments: TeacherComment[] }>
|
|
42
|
-
assignmentId: string
|
|
43
|
-
}
|
|
44
|
-
>
|
|
34
|
+
getCommentsByAssignmentIdFx: Effect<GetCommentsByIdProps, Record<string, { comments: TeacherComment[] }>>
|
|
45
35
|
updateCommentSeenFx: Effect<UpdateCommentSeenStatusProps, void>
|
|
46
36
|
|
|
47
37
|
sockets = {
|
|
@@ -50,15 +40,8 @@ export class TeacherFeedbackModel {
|
|
|
50
40
|
}
|
|
51
41
|
|
|
52
42
|
constructor({ api, credits }: TeacherFeedbackModelProps) {
|
|
53
|
-
this.getCommentsByAssignmentIdFx = createEffect(
|
|
54
|
-
const response = await api.getCommentsByAssignmentId({ id })
|
|
55
|
-
return {
|
|
56
|
-
data: response,
|
|
57
|
-
assignmentId: id,
|
|
58
|
-
}
|
|
59
|
-
})
|
|
43
|
+
this.getCommentsByAssignmentIdFx = createEffect(api.getCommentsByAssignmentId)
|
|
60
44
|
this.updateCommentSeenFx = createEffect(api.updateCommentSeenStatus)
|
|
61
|
-
this.$assignmentId = credits.assignmentId
|
|
62
45
|
this.$currentProblemId = credits.problemId
|
|
63
46
|
this.$locale = credits.locale
|
|
64
47
|
|
|
@@ -70,13 +53,10 @@ export class TeacherFeedbackModel {
|
|
|
70
53
|
|
|
71
54
|
sample({
|
|
72
55
|
clock: this.sockets.onCreate,
|
|
73
|
-
source: [this.$isOpened, this.$currentProblemId
|
|
74
|
-
filter: ([isOpen
|
|
75
|
-
|
|
76
|
-
},
|
|
77
|
-
fn: ([_, currentProblemId, assignmentId], { _id }) => ({
|
|
56
|
+
source: [this.$isOpened, this.$currentProblemId] as const,
|
|
57
|
+
filter: ([isOpen]) => isOpen,
|
|
58
|
+
fn: ([_, currentProblemId], { _id }) => ({
|
|
78
59
|
currentProblemId,
|
|
79
|
-
assignmentId,
|
|
80
60
|
ids: [_id],
|
|
81
61
|
}),
|
|
82
62
|
target: [this.setCommentsSeen, this.updateCommentSeenFx],
|
|
@@ -84,50 +64,42 @@ export class TeacherFeedbackModel {
|
|
|
84
64
|
|
|
85
65
|
sample({
|
|
86
66
|
clock: this.$isOpened,
|
|
87
|
-
source: [this.$comments, this.$currentProblemId
|
|
88
|
-
filter: ([feedback, currentProblemId
|
|
89
|
-
const
|
|
90
|
-
const comments = assignmentComments[currentProblemId]?.comments ?? []
|
|
67
|
+
source: [this.$comments, this.$currentProblemId] as const,
|
|
68
|
+
filter: ([feedback, currentProblemId], isOpen) => {
|
|
69
|
+
const comments = feedback.get(currentProblemId)?.comments ?? []
|
|
91
70
|
const hasUnreadComments = comments.some((comment) => !comment.isRead)
|
|
92
71
|
return isOpen && hasUnreadComments
|
|
93
72
|
},
|
|
94
|
-
fn: ([feedback, currentProblemId
|
|
95
|
-
const
|
|
96
|
-
const comments = assignmentComments[currentProblemId]?.comments ?? []
|
|
73
|
+
fn: ([feedback, currentProblemId]) => {
|
|
74
|
+
const comments = feedback.get(currentProblemId)?.comments ?? []
|
|
97
75
|
return {
|
|
98
76
|
currentProblemId,
|
|
99
|
-
assignmentId,
|
|
100
77
|
ids: comments.filter((comment) => !comment.isRead).map((comment) => comment._id),
|
|
101
78
|
}
|
|
102
79
|
},
|
|
103
80
|
target: [this.setCommentsSeen, this.updateCommentSeenFx],
|
|
104
81
|
})
|
|
105
82
|
|
|
106
|
-
this.$isVisible.on(this.getCommentsByAssignmentIdFx.doneData, (_,
|
|
107
|
-
return Object.values(
|
|
83
|
+
this.$isVisible.on(this.getCommentsByAssignmentIdFx.doneData, (_, payload) => {
|
|
84
|
+
return Object.values(payload).some((problemFeedback) => problemFeedback.comments?.length > 0)
|
|
108
85
|
})
|
|
109
86
|
|
|
110
87
|
this.$comments
|
|
111
|
-
.on(this.getCommentsByAssignmentIdFx.doneData, (
|
|
112
|
-
const
|
|
88
|
+
.on(this.getCommentsByAssignmentIdFx.doneData, (_, payload) => {
|
|
89
|
+
const state = new Map()
|
|
113
90
|
|
|
114
|
-
for (const [problemId, { comments }] of Object.entries(
|
|
91
|
+
for (const [problemId, { comments }] of Object.entries(payload)) {
|
|
115
92
|
const unreadMessages = comments.filter((comment) => !comment.isRead)
|
|
116
|
-
|
|
93
|
+
state.set(problemId, {
|
|
117
94
|
comments,
|
|
118
95
|
unreadMessagesCount: unreadMessages.length,
|
|
119
|
-
}
|
|
96
|
+
})
|
|
120
97
|
}
|
|
121
98
|
|
|
122
|
-
|
|
123
|
-
updatedState.set(assignmentId, problemsMap)
|
|
124
|
-
return updatedState
|
|
99
|
+
return state
|
|
125
100
|
})
|
|
126
|
-
.on(this.setCommentsSeen, (state, { ids, currentProblemId
|
|
127
|
-
const
|
|
128
|
-
if (!assignmentComments) return state
|
|
129
|
-
|
|
130
|
-
const feedback = assignmentComments[currentProblemId]
|
|
101
|
+
.on(this.setCommentsSeen, (state, { ids, currentProblemId }) => {
|
|
102
|
+
const feedback = state.get(currentProblemId)
|
|
131
103
|
if (!feedback) return state
|
|
132
104
|
|
|
133
105
|
const updatedComments = feedback.comments.map((comment) =>
|
|
@@ -140,19 +112,13 @@ export class TeacherFeedbackModel {
|
|
|
140
112
|
unreadMessagesCount: 0,
|
|
141
113
|
}
|
|
142
114
|
|
|
143
|
-
const updatedAssignmentComments = {
|
|
144
|
-
...assignmentComments,
|
|
145
|
-
[currentProblemId]: updatedFeedback,
|
|
146
|
-
}
|
|
147
|
-
|
|
148
115
|
const updatedState = new Map(state)
|
|
149
|
-
updatedState.set(
|
|
116
|
+
updatedState.set(currentProblemId, updatedFeedback)
|
|
150
117
|
|
|
151
118
|
return updatedState
|
|
152
119
|
})
|
|
153
120
|
.on(this.sockets.onCreate, (state, payload) => {
|
|
154
|
-
const
|
|
155
|
-
const feedback = assignmentComments[payload.problemId] ?? { comments: [], unreadMessagesCount: 0 }
|
|
121
|
+
const feedback = state.get(payload.problemId) ?? { comments: [], unreadMessagesCount: 0 }
|
|
156
122
|
|
|
157
123
|
const updatedFeedback = {
|
|
158
124
|
...feedback,
|
|
@@ -160,22 +126,13 @@ export class TeacherFeedbackModel {
|
|
|
160
126
|
unreadMessagesCount: feedback.unreadMessagesCount + 1,
|
|
161
127
|
}
|
|
162
128
|
|
|
163
|
-
const updatedAssignmentComments = {
|
|
164
|
-
...assignmentComments,
|
|
165
|
-
[payload.problemId]: updatedFeedback,
|
|
166
|
-
}
|
|
167
|
-
|
|
168
129
|
const updatedState = new Map(state)
|
|
169
|
-
updatedState.set(payload.
|
|
130
|
+
updatedState.set(payload.problemId, updatedFeedback)
|
|
170
131
|
|
|
171
132
|
return updatedState
|
|
172
133
|
})
|
|
173
134
|
.on(this.sockets.onDeleted, (state, payload) => {
|
|
174
|
-
const
|
|
175
|
-
const assignmentComments = state.get(assignmentId)
|
|
176
|
-
if (!assignmentComments) return state
|
|
177
|
-
|
|
178
|
-
const feedback = assignmentComments[payload.problemId]
|
|
135
|
+
const feedback = state.get(payload.problemId)
|
|
179
136
|
if (!feedback) return state
|
|
180
137
|
|
|
181
138
|
const isDeleteMessageUnread = feedback.comments.some(
|
|
@@ -187,65 +144,35 @@ export class TeacherFeedbackModel {
|
|
|
187
144
|
unreadMessagesCount: isDeleteMessageUnread ? feedback.unreadMessagesCount - 1 : feedback.unreadMessagesCount,
|
|
188
145
|
}
|
|
189
146
|
|
|
147
|
+
const updatedState = new Map(state)
|
|
190
148
|
const isOpen = this.$isOpened.getState()
|
|
191
149
|
|
|
192
150
|
if (updatedFeedback.comments.length === 0) {
|
|
193
|
-
const updatedAssignmentComments = { ...assignmentComments }
|
|
194
|
-
|
|
195
151
|
if (!isOpen) {
|
|
196
|
-
delete
|
|
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
|
-
}
|
|
152
|
+
updatedState.delete(payload.problemId)
|
|
153
|
+
return updatedState
|
|
209
154
|
}
|
|
210
155
|
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
156
|
+
const feedbackWithCustomMessage = { ...updatedFeedback }
|
|
157
|
+
feedbackWithCustomMessage.comments = [getEmptyComment(payload.problemId, this.$locale.getState())]
|
|
158
|
+
updatedState.set(payload.problemId, feedbackWithCustomMessage)
|
|
215
159
|
|
|
216
|
-
|
|
217
|
-
...assignmentComments,
|
|
218
|
-
[payload.problemId]: updatedFeedback,
|
|
160
|
+
return updatedState
|
|
219
161
|
}
|
|
220
162
|
|
|
221
|
-
|
|
222
|
-
updatedState.set(assignmentId, updatedAssignmentComments)
|
|
163
|
+
updatedState.set(payload.problemId, updatedFeedback)
|
|
223
164
|
return updatedState
|
|
224
165
|
})
|
|
225
166
|
.on(this.setIsOpened, (state, isOpen) => {
|
|
226
167
|
if (isOpen) return state
|
|
227
168
|
|
|
228
|
-
const assignmentId = this.$assignmentId.getState()
|
|
229
169
|
const problemId = this.$currentProblemId.getState()
|
|
230
|
-
const
|
|
231
|
-
if (!assignmentComments) return state
|
|
232
|
-
|
|
233
|
-
const feedback = assignmentComments[problemId]
|
|
170
|
+
const feedback = state.get(problemId)
|
|
234
171
|
if (!feedback) return state
|
|
235
172
|
|
|
236
173
|
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
|
-
|
|
247
174
|
const updatedState = new Map(state)
|
|
248
|
-
updatedState.
|
|
175
|
+
updatedState.delete(problemId)
|
|
249
176
|
return updatedState
|
|
250
177
|
}
|
|
251
178
|
|