@@ -16,6 +16,7 @@ import TaskHeaderActionButton from '@components/TaskHeaderActionButton';
16
16
import withCurrentReportID , { withCurrentReportIDDefaultProps , withCurrentReportIDPropTypes } from '@components/withCurrentReportID' ;
17
17
import withViewportOffsetTop from '@components/withViewportOffsetTop' ;
18
18
import useLocalize from '@hooks/useLocalize' ;
19
+ import useNetwork from '@hooks/useNetwork' ;
19
20
import usePrevious from '@hooks/usePrevious' ;
20
21
import useWindowDimensions from '@hooks/useWindowDimensions' ;
21
22
import compose from '@libs/compose' ;
@@ -152,6 +153,7 @@ function ReportScreen({
152
153
const styles = useThemeStyles ( ) ;
153
154
const { translate} = useLocalize ( ) ;
154
155
const { isSmallScreenWidth} = useWindowDimensions ( ) ;
156
+ const { isOffline} = useNetwork ( ) ;
155
157
156
158
const firstRenderRef = useRef ( true ) ;
157
159
const flatListRef = useRef ( ) ;
@@ -166,8 +168,11 @@ function ReportScreen({
166
168
const { addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors} = ReportUtils . getReportOfflinePendingActionAndErrors ( report ) ;
167
169
const screenWrapperStyle = [ styles . appContent , styles . flex1 , { marginTop : viewportOffsetTop } ] ;
168
170
171
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- need to re-filter the report actions when network status changes
172
+ const filteredReportActions = useMemo ( ( ) => ReportActionsUtils . getSortedReportActionsForDisplay ( reportActions , true ) , [ isOffline , reportActions ] ) ;
173
+
169
174
// There are no reportActions at all to display and we are still in the process of loading the next set of actions.
170
- const isLoadingInitialReportActions = _ . isEmpty ( reportActions ) && reportMetadata . isLoadingInitialReportActions ;
175
+ const isLoadingInitialReportActions = _ . isEmpty ( filteredReportActions ) && reportMetadata . isLoadingInitialReportActions ;
171
176
172
177
const isOptimisticDelete = lodashGet ( report , 'statusNum' ) === CONST . REPORT . STATUS . CLOSED ;
173
178
@@ -422,7 +427,7 @@ function ReportScreen({
422
427
>
423
428
{ isReportReadyForDisplay && ! isLoadingInitialReportActions && ! isLoading && (
424
429
< ReportActionsView
425
- reportActions = { reportActions }
430
+ reportActions = { filteredReportActions }
426
431
report = { report }
427
432
isLoadingInitialReportActions = { reportMetadata . isLoadingInitialReportActions }
428
433
isLoadingNewerReportActions = { reportMetadata . isLoadingNewerReportActions }
@@ -440,7 +445,7 @@ function ReportScreen({
440
445
{ isReportReadyForDisplay ? (
441
446
< ReportFooter
442
447
pendingAction = { addWorkspaceRoomOrChatPendingAction }
443
- reportActions = { reportActions }
448
+ reportActions = { filteredReportActions }
444
449
report = { report }
445
450
isComposerFullSize = { isComposerFullSize }
446
451
onSubmitComment = { onSubmitComment }
@@ -475,7 +480,6 @@ export default compose(
475
480
reportActions : {
476
481
key : ( { route} ) => `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ getReportID ( route ) } ` ,
477
482
canEvict : false ,
478
- selector : ( reportActions ) => ReportActionsUtils . getSortedReportActionsForDisplay ( reportActions , true ) ,
479
483
} ,
480
484
report : {
481
485
key : ( { route} ) => `${ ONYXKEYS . COLLECTION . REPORT } ${ getReportID ( route ) } ` ,
0 commit comments