@@ -3,21 +3,59 @@ import { Typography, useTheme } from '@mui/material';
33
44import { StudentStatusValues } from '../../../../services/StudentStatus' ;
55import { UserDataContext } from '../../../../contexts/UserDataContext' ;
6+ import { QueueDataContext } from '../../../../contexts/QueueDataContext' ;
67
78export default function StudentStatus ( props ) {
8- const { student } = props ;
9+ const { student, currentTime } = props ;
910 const theme = useTheme ( ) ;
1011
1112 const { userData } = useContext ( UserDataContext ) ;
13+ const { queueData } = useContext ( QueueDataContext ) ;
1214
1315 const status = student . status ;
1416
17+ const formatTime = ( seconds ) => {
18+ // Handle negative or zero seconds
19+ if ( seconds <= 0 ) return '0:00' ;
20+
21+ const minutes = Math . floor ( seconds / 60 ) ;
22+ const remainingSeconds = seconds % 60 ;
23+ return `${ minutes } :${ remainingSeconds < 10 ? '0' : '' } ${ remainingSeconds } ` ;
24+ } ;
25+
26+ // Calculate elapsed time based on the provided currentTime
27+ const getElapsedTime = ( ) => {
28+ if (
29+ status === StudentStatusValues . BEING_HELPED &&
30+ student . helpingTAInfo ?. helpStartTime
31+ ) {
32+ const startTime = new Date ( student . helpingTAInfo . helpStartTime ) . getTime ( ) ;
33+ return Math . floor ( ( currentTime - startTime ) / 1000 ) ;
34+ }
35+ return 0 ;
36+ } ;
37+
1538 const chooseText = ( status ) => {
1639 switch ( status ) {
1740 case StudentStatusValues . BEING_HELPED : {
1841 if ( student . helpingTAInfo ?. taAndrewID === userData . andrewID ) {
42+ // Show self timer if enabled
43+ if (
44+ userData . taSettings ?. showSelfTimer &&
45+ student . helpingTAInfo ?. helpStartTime
46+ ) {
47+ return `You have been helping for ${ formatTime ( getElapsedTime ( ) ) } ` ;
48+ }
1949 return 'You are helping' ;
2050 } else {
51+ // Show others timer if enabled (both user setting and admin setting)
52+ if (
53+ userData . taSettings ?. showOthersTimer &&
54+ queueData . allowShowOthersTimer &&
55+ student . helpingTAInfo ?. helpStartTime
56+ ) {
57+ return `${ student ?. helpingTAInfo ?. taPrefName } has been helping for ${ formatTime ( getElapsedTime ( ) ) } ` ;
58+ }
2159 return `${ student ?. helpingTAInfo ?. taPrefName } is Helping` ;
2260 }
2361 }
0 commit comments