@@ -7,46 +7,46 @@ import { useMemo } from 'react';
77 * The backend determines learner status based on actual engagement metrics and enrollment data.
88 *
99 * @param {Object } postData - The thread or comment data from the API that includes learner fields
10- * @param {string } author - The username of the author; used to check for anonymous and retired users to suppress learner messages
10+ * @param {string } author - The username of the author; used to check for anonymous and retired users
11+ * to suppress learner messages
1112 * @param {string } authorLabel - The author's role label (Staff, Moderator, etc.)
1213 * @returns {Object } - { isNewLearner: boolean, isRegularLearner: boolean }
1314 */
14- export const useLearnerStatus = ( postData , author , authorLabel ) => useMemo ( ( ) => {
15- // Users with special roles (Staff, Moderator, Community TA) should not display learner messages
16- // Anonymous and retired users should also not display learner messages
17- if (
18- authorLabel
19- || author === 'anonymous'
20- || ( author && author . startsWith ( 'retired__user' ) )
21- ) {
22- return {
23- isNewLearner : false ,
24- isRegularLearner : false ,
25- } ;
26- }
15+ export const useLearnerStatus = ( postData , author , authorLabel ) =>
16+ useMemo ( ( ) => {
17+ // Users with special roles (Staff, Moderator, Community TA) should not display learner messages
18+ // Anonymous and retired users should also not display learner messages
19+ if (
20+ authorLabel ||
21+ author === 'anonymous' ||
22+ ( author && author . startsWith ( 'retired__user' ) )
23+ ) {
24+ return {
25+ isNewLearner : false ,
26+ isRegularLearner : false ,
27+ } ;
28+ }
2729
28- // Always rely on backend-provided fields
29- // Note: Backend sends 'is_new_learner'/'is_regular_learner' but frontend may transform to camelCase
30- if ( postData && typeof postData === 'object' ) {
31- const isNewLearner = postData . isNewLearner
32- || postData . is_new_learner
33- || false ;
34- const isRegularLearner = postData . isRegularLearner
35- || postData . is_regular_learner
36- || false ;
30+ // Always rely on backend-provided fields
31+ // Note: Backend sends 'is_new_learner'/'is_regular_learner' but frontend may transform to camelCase
32+ if ( postData && typeof postData === 'object' ) {
33+ const isNewLearner =
34+ postData . isNewLearner || postData . is_new_learner || false ;
35+ const isRegularLearner =
36+ postData . isRegularLearner || postData . is_regular_learner || false ;
3737
38+ return {
39+ isNewLearner,
40+ isRegularLearner,
41+ } ;
42+ }
43+
44+ // If postData is not available, return false for both
45+ // Do not attempt client-side detection as it would produce false positives
3846 return {
39- isNewLearner,
40- isRegularLearner,
47+ isNewLearner : false ,
48+ isRegularLearner : false ,
4149 } ;
42- }
43-
44- // If postData is not available, return false for both
45- // Do not attempt client-side detection as it would produce false positives
46- return {
47- isNewLearner : false ,
48- isRegularLearner : false ,
49- } ;
50- } , [ postData , author , authorLabel ] ) ;
50+ } , [ postData , author , authorLabel ] ) ;
5151
5252export default useLearnerStatus ;
0 commit comments