Skip to content

Commit

Permalink
Revert "Fix - Attachment - Unable to download a txt attachment until …
Browse files Browse the repository at this point in the history
…the browser is refreshed"
  • Loading branch information
Beamanator authored Oct 17, 2024
1 parent a0ebba0 commit 50915dd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ type BaseAnchorForAttachmentsOnlyProps = AnchorForAttachmentsOnlyProps & {
function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', onPressIn, onPressOut}: BaseAnchorForAttachmentsOnlyProps) {
const sourceURLWithAuth = addEncryptedAuthTokenToURL(source);
const sourceID = (source.match(CONST.REGEX.ATTACHMENT_ID) ?? [])[1];

const [download] = useOnyx(`${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`);

const {isOffline} = useNetwork();
const styles = useThemeStyles();

Expand All @@ -37,7 +35,7 @@ function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', onP
<ShowContextMenuContext.Consumer>
{({anchor, report, reportNameValuePairs, action, checkIfContextMenuActive, isDisabled}) => (
<PressableWithoutFeedback
style={[style, (isOffline || !sourceID) && styles.cursorDefault]}
style={[style, isOffline && styles.cursorDefault]}
onPress={() => {
if (isDownloading || isOffline || !sourceID) {
return;
Expand All @@ -63,7 +61,6 @@ function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', onP
shouldShowDownloadIcon={!!sourceID && !isOffline}
shouldShowLoadingSpinnerIcon={isDownloading}
isUsedAsChatAttachment
isUploading={!sourceID}
/>
</PressableWithoutFeedback>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ type DefaultAttachmentViewProps = {
containerStyles?: StyleProp<ViewStyle>;

icon?: IconAsset;

/** Flag indicating if the attachment is being uploaded. */
isUploading?: boolean;
};

function DefaultAttachmentView({fileName = '', shouldShowLoadingSpinnerIcon = false, shouldShowDownloadIcon, containerStyles, icon, isUploading}: DefaultAttachmentViewProps) {
function DefaultAttachmentView({fileName = '', shouldShowLoadingSpinnerIcon = false, shouldShowDownloadIcon, containerStyles, icon}: DefaultAttachmentViewProps) {
const theme = useTheme();
const styles = useThemeStyles();
const {translate} = useLocalize();
Expand All @@ -56,7 +53,7 @@ function DefaultAttachmentView({fileName = '', shouldShowLoadingSpinnerIcon = fa
)}
{shouldShowLoadingSpinnerIcon && (
<View style={styles.ml2}>
<Tooltip text={isUploading ? translate('common.uploading') : translate('common.downloading')}>
<Tooltip text={translate('common.downloading')}>
<ActivityIndicator
size="small"
color={theme.textSupporting}
Expand Down
87 changes: 45 additions & 42 deletions src/components/Attachments/AttachmentView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {Str} from 'expensify-common';
import React, {memo, useContext, useEffect, useState} from 'react';
import type {GestureResponderEvent, StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext';
import type {Attachment, AttachmentSource} from '@components/Attachments/types';
import DistanceEReceipt from '@components/DistanceEReceipt';
Expand All @@ -23,58 +24,60 @@ import * as TransactionUtils from '@libs/TransactionUtils';
import type {ColorValue} from '@styles/utils/types';
import variables from '@styles/variables';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Transaction} from '@src/types/onyx';
import AttachmentViewImage from './AttachmentViewImage';
import AttachmentViewPdf from './AttachmentViewPdf';
import AttachmentViewVideo from './AttachmentViewVideo';
import DefaultAttachmentView from './DefaultAttachmentView';
import HighResolutionInfo from './HighResolutionInfo';

type AttachmentViewProps = Attachment & {
/** Whether this view is the active screen */
isFocused?: boolean;
type AttachmentViewOnyxProps = {
transaction: OnyxEntry<Transaction>;
};

/** Function for handle on press */
onPress?: (e?: GestureResponderEvent | KeyboardEvent) => void;
type AttachmentViewProps = AttachmentViewOnyxProps &
Attachment & {
/** Whether this view is the active screen */
isFocused?: boolean;

/** Whether the attachment is used in attachment modal */
isUsedInAttachmentModal?: boolean;
/** Function for handle on press */
onPress?: (e?: GestureResponderEvent | KeyboardEvent) => void;

/** Flag to show/hide download icon */
shouldShowDownloadIcon?: boolean;
isUsedInAttachmentModal?: boolean;

/** Flag to show the loading indicator */
shouldShowLoadingSpinnerIcon?: boolean;
/** Flag to show/hide download icon */
shouldShowDownloadIcon?: boolean;

/** Notify parent that the UI should be modified to accommodate keyboard */
onToggleKeyboard?: (shouldFadeOut: boolean) => void;
/** Flag to show the loading indicator */
shouldShowLoadingSpinnerIcon?: boolean;

/** A callback when the PDF fails to load */
onPDFLoadError?: () => void;
/** Notify parent that the UI should be modified to accommodate keyboard */
onToggleKeyboard?: (shouldFadeOut: boolean) => void;

/** Extra styles to pass to View wrapper */
containerStyles?: StyleProp<ViewStyle>;
/** A callback when the PDF fails to load */
onPDFLoadError?: () => void;

/** Denotes whether it is a workspace avatar or not */
isWorkspaceAvatar?: boolean;
/** Extra styles to pass to View wrapper */
containerStyles?: StyleProp<ViewStyle>;

/** Denotes whether it is an icon (ex: SVG) */
maybeIcon?: boolean;
/** Denotes whether it is a workspace avatar or not */
isWorkspaceAvatar?: boolean;

/** Fallback source to use in case of error */
fallbackSource?: AttachmentSource;
/** Denotes whether it is an icon (ex: SVG) */
maybeIcon?: boolean;

/* Whether it is hovered or not */
isHovered?: boolean;
/** Fallback source to use in case of error */
fallbackSource?: AttachmentSource;

/** Whether the attachment is used as a chat attachment */
isUsedAsChatAttachment?: boolean;
/* Whether it is hovered or not */
isHovered?: boolean;

/* Flag indicating whether the attachment has been uploaded. */
isUploaded?: boolean;
/** Whether the attachment is used as a chat attachment */
isUsedAsChatAttachment?: boolean;

/** Flag indicating if the attachment is being uploaded. */
isUploading?: boolean;
};
/* Flag indicating whether the attachment has been uploaded. */
isUploaded?: boolean;
};

function AttachmentView({
source,
Expand All @@ -92,20 +95,16 @@ function AttachmentView({
isWorkspaceAvatar,
maybeIcon,
fallbackSource,
transactionID = '-1',
transaction,
reportActionID,
isHovered,
duration,
isUsedAsChatAttachment,
isUploaded = true,
isUploading = false,
}: AttachmentViewProps) {
const {translate} = useLocalize();
const {updateCurrentlyPlayingURL} = usePlaybackContext();
const attachmentCarouselPagerContext = useContext(AttachmentCarouselPagerContext);

const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);

const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand Down Expand Up @@ -289,16 +288,20 @@ function AttachmentView({
<DefaultAttachmentView
fileName={file?.name}
shouldShowDownloadIcon={shouldShowDownloadIcon}
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
shouldShowLoadingSpinnerIcon={shouldShowLoadingSpinnerIcon || isUploading}
shouldShowLoadingSpinnerIcon={shouldShowLoadingSpinnerIcon}
containerStyles={containerStyles}
isUploading={isUploading}
/>
);
}

AttachmentView.displayName = 'AttachmentView';

export default memo(AttachmentView);
export default memo(
withOnyx<AttachmentViewProps, AttachmentViewOnyxProps>({
transaction: {
key: ({transactionID}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
},
})(AttachmentView),
);

export type {AttachmentViewProps};
1 change: 0 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ const translations = {
close: 'Close',
download: 'Download',
downloading: 'Downloading',
uploading: 'Uploading',
pin: 'Pin',
unPin: 'Unpin',
back: 'Back',
Expand Down
1 change: 0 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ const translations = {
close: 'Cerrar',
download: 'Descargar',
downloading: 'Descargando',
uploading: 'Subiendo',
pin: 'Fijar',
unPin: 'Desfijar',
back: 'Volver',
Expand Down

0 comments on commit 50915dd

Please sign in to comment.