-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39290 from FitseTLT/fix-attachement-offline-indic…
…ator Fix - Attachment page keeps on loading infinitely.
- Loading branch information
Showing
10 changed files
with
88 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, {useEffect, useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useNetwork from '@hooks/useNetwork'; | ||
import useTheme from '@hooks/useTheme'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import variables from '@styles/variables'; | ||
import Icon from './Icon'; | ||
import * as Expensicons from './Icon/Expensicons'; | ||
import Text from './Text'; | ||
|
||
type AttachmentOfflineIndicatorProps = { | ||
/** Whether the offline indicator is displayed for the attachment preview. */ | ||
isPreview?: boolean; | ||
}; | ||
|
||
function AttachmentOfflineIndicator({isPreview = false}: AttachmentOfflineIndicatorProps) { | ||
const theme = useTheme(); | ||
const styles = useThemeStyles(); | ||
const {isOffline} = useNetwork(); | ||
const {translate} = useLocalize(); | ||
|
||
// We don't want to show the offline indicator when the attachment is a cached one, so | ||
// we delay the display by 200 ms to ensure it is not a cached one. | ||
const [onCacheDelay, setOnCacheDelay] = useState(true); | ||
|
||
useEffect(() => { | ||
const timeout = setTimeout(() => setOnCacheDelay(false), 200); | ||
|
||
return () => clearTimeout(timeout); | ||
}, []); | ||
|
||
if (!isOffline || onCacheDelay) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<View style={[styles.flexColumn, styles.alignItemsCenter, styles.justifyContentCenter, styles.pAbsolute, styles.h100, styles.w100, isPreview && styles.hoveredComponentBG]}> | ||
<Icon | ||
fill={theme.border} | ||
src={Expensicons.OfflineCloud} | ||
width={variables.iconSizeSuperLarge} | ||
height={variables.iconSizeSuperLarge} | ||
/> | ||
{!isPreview && ( | ||
<View> | ||
<Text style={[styles.notFoundTextHeader]}>{translate('common.youAppearToBeOffline')}</Text> | ||
<Text>{translate('common.attachementWillBeAvailableOnceBackOnline')}</Text> | ||
</View> | ||
)} | ||
</View> | ||
); | ||
} | ||
|
||
AttachmentOfflineIndicator.displayName = 'AttachmentOfflineIndicator'; | ||
|
||
export default AttachmentOfflineIndicator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters