Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: When user goes offline, the download button do not disappear for other file types. #35324

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 (
<ShowContextMenuContext.Consumer>
{({anchor, report, action, checkIfContextMenuActive}) => (
<PressableWithoutFeedback
style={style}
style={[style, isOffline && styles.cursorDefault]}
onPress={() => {
if (isDownloading) {
if (isDownloading || isOffline) {
return;
}
Download.setDownload(sourceID, true);
Expand All @@ -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}
/>
</PressableWithoutFeedback>
Expand Down
Loading