From fd4e5f0282a6ba6a696456968e3d08cc71861b2a Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Mon, 29 Jan 2024 22:27:09 +0530 Subject: [PATCH] fix: When user goes offline, the download button do not disappear for other file types. Signed-off-by: Krishna Gupta --- .../BaseAnchorForAttachmentsOnly.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx index df8a0a30b129..33409f855bec 100644 --- a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx +++ b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx @@ -4,6 +4,8 @@ import type {OnyxEntry} from 'react-native-onyx'; import AttachmentView from '@components/Attachments/AttachmentView'; import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback'; import {ShowContextMenuContext, showContextMenuForReport} from '@components/ShowContextMenuContext'; +import useNetwork from '@hooks/useNetwork'; +import useThemeStyles from '@hooks/useThemeStyles'; import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import fileDownload from '@libs/fileDownload'; import * as ReportUtils from '@libs/ReportUtils'; @@ -31,15 +33,18 @@ function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', dow const sourceURLWithAuth = addEncryptedAuthTokenToURL(source); const sourceID = (source.match(CONST.REGEX.ATTACHMENT_ID) ?? [])[1]; + const {isOffline} = useNetwork(); + const styles = useThemeStyles(); + const isDownloading = download?.isDownloading ?? false; return ( {({anchor, report, action, checkIfContextMenuActive}) => ( { - if (isDownloading) { + if (isDownloading || isOffline) { return; } Download.setDownload(sourceID, true); @@ -56,7 +61,7 @@ function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', dow // @ts-expect-error TODO: Remove this once AttachmentView (https://github.com/Expensify/App/issues/25150) is migrated to TypeScript. source={sourceURLWithAuth} file={{name: displayName}} - shouldShowDownloadIcon + shouldShowDownloadIcon={!isOffline} shouldShowLoadingSpinnerIcon={isDownloading} />