@@ -9,6 +9,7 @@ import {isReportParticipant, isValidReport} from '@libs/ReportUtils';
99import CONST from '@src/CONST' ;
1010import ONYXKEYS from '@src/ONYXKEYS' ;
1111import SCREENS from '@src/SCREENS' ;
12+ import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue' ;
1213import FocusModeNotification from './FocusModeNotification' ;
1314
1415/**
@@ -25,13 +26,12 @@ import FocusModeNotification from './FocusModeNotification';
2526export default function PriorityModeController ( ) {
2627 const [ accountID ] = useOnyx ( ONYXKEYS . SESSION , { selector : ( session ) => session ?. accountID , canBeMissing : true } ) ;
2728 const [ isLoadingReportData ] = useOnyx ( ONYXKEYS . IS_LOADING_REPORT_DATA , { canBeMissing : true } ) ;
28- const [ isInFocusMode ] = useOnyx ( ONYXKEYS . NVP_PRIORITY_MODE , { selector : ( priorityMode ) => priorityMode === CONST . PRIORITY_MODE . GSD , canBeMissing : true } ) ;
29- const [ hasTriedFocusMode ] = useOnyx ( ONYXKEYS . NVP_TRY_FOCUS_MODE , { canBeMissing : true } ) ;
29+ const [ isInFocusMode , isInFocusModeMetadata ] = useOnyx ( ONYXKEYS . NVP_PRIORITY_MODE , { selector : ( priorityMode ) => priorityMode === CONST . PRIORITY_MODE . GSD , canBeMissing : true } ) ;
30+ const [ hasTriedFocusMode , hasTriedFocusModeMetadata ] = useOnyx ( ONYXKEYS . NVP_TRY_FOCUS_MODE , { canBeMissing : true } ) ;
3031 const [ allReports ] = useOnyx ( ONYXKEYS . COLLECTION . REPORT , { canBeMissing : true } ) ;
3132 const currentRouteName = useCurrentRouteName ( ) ;
3233 const [ shouldShowModal , setShouldShowModal ] = useState ( false ) ;
3334 const closeModal = useCallback ( ( ) => setShouldShowModal ( false ) , [ ] ) ;
34-
3535 const validReportCount = useMemo ( ( ) => {
3636 let count = 0 ;
3737 Object . values ( allReports ?? { } ) . forEach ( ( report ) => {
@@ -50,10 +50,11 @@ export default function PriorityModeController() {
5050 // Listen for state changes and trigger the #focus mode when appropriate
5151 useEffect ( ( ) => {
5252 // Wait for Onyx state to fully load
53- if ( isLoadingReportData !== false || isInFocusMode === undefined || hasTriedFocusMode === undefined || ! accountID ) {
53+ if ( isLoadingReportData !== false || ! accountID || isLoadingOnyxValue ( isInFocusModeMetadata , hasTriedFocusModeMetadata ) ) {
5454 return ;
5555 }
5656
57+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
5758 if ( hasSwitched . current || isInFocusMode || hasTriedFocusMode ) {
5859 return ;
5960 }
@@ -74,7 +75,7 @@ export default function PriorityModeController() {
7475 updateChatPriorityMode ( CONST . PRIORITY_MODE . GSD , true ) ;
7576 setShouldShowModal ( true ) ;
7677 hasSwitched . current = true ;
77- } , [ accountID , currentRouteName , hasTriedFocusMode , isInFocusMode , isLoadingReportData , validReportCount ] ) ;
78+ } , [ accountID , currentRouteName , hasTriedFocusMode , hasTriedFocusModeMetadata , isInFocusMode , isInFocusModeMetadata , isLoadingReportData , validReportCount ] ) ;
7879
7980 return shouldShowModal ? < FocusModeNotification onClose = { closeModal } /> : null ;
8081}
0 commit comments