@@ -2,7 +2,7 @@ import React, {createContext, useEffect, useState, useContext} from 'react';
22import { StudentData } from '../../../types/StudentData' ;
33import { UserDataContext } from '../contexts/UserDataContext' ;
44import HomeService from '../services/HomeService' ;
5- import { socketSubscribeTo } from '../services/SocketsService' ;
5+ import { ensureSocketConnected , socketSubscribeTo } from '../services/SocketsService' ;
66import { StudentStatusValues } from '../services/StudentStatus' ;
77
88/**
@@ -65,19 +65,24 @@ const StudentDataContextProvider = ({children}: {children: React.ReactNode}) =>
6565 socketSubscribeTo ( 'studentData' , ( data : StudentData ) => {
6666 if ( data . andrewID === userData . andrewID ) {
6767 setStudentData ( data ) ;
68+ } else {
69+ console . log ( 'Student data id doesn\'t match andrewID' ) ;
6870 }
6971 } ) ;
7072
71- // const handleVisibilityChange = () => {
72- // if (document.visibilityState === 'visible') {
73- // HomeService.getStudentData().then((res) => {
74- // if (res.status === 200 && res.data.andrewID === userData.andrewID) {
75- // setStudentData(res.data);
76- // }
77- // });
78- // }
79- // };
80- // document.addEventListener('visibilitychange', handleVisibilityChange);
73+ const handleVisibilityChange = ( ) => {
74+ if ( document . visibilityState === 'visible' ) {
75+ HomeService . getStudentData ( ) . then ( ( res ) => {
76+ if ( res . status === 200 && res . data . andrewID === userData . andrewID ) {
77+ setStudentData ( res . data ) ;
78+ } else if ( res . data . andrewID === userData . andrewID ) {
79+ console . log ( 'Student data id doesn\'t match andrewID' ) ;
80+ }
81+ ensureSocketConnected ( ) ;
82+ } ) ;
83+ }
84+ } ;
85+ document . addEventListener ( 'visibilitychange' , handleVisibilityChange ) ;
8186 }
8287 } , [ userData . isAuthenticated ] ) ;
8388
0 commit comments