Skip to content

Commit

Permalink
set up attachment download to work
Browse files Browse the repository at this point in the history
  • Loading branch information
JediWattson committed Sep 5, 2022
1 parent 19d648a commit 59e461c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
14 changes: 2 additions & 12 deletions src/components/AttachmentCarousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class AttachmentCarousel extends React.Component {

this.canUseTouchScreen = canUseTouchScreen();
this.makeAndSetArrowState = this.makeAndSetArrowState.bind(this);
this.onPressShowArrow = this.onPressShowArrow.bind(this);
this.cycleThroughAttachments = this.cycleThroughAttachments.bind(this);
this.handleArrowPress = this.handleArrowPress.bind(this);
this.onShowArrow = this.onShowArrow.bind(this);
Expand Down Expand Up @@ -72,23 +71,13 @@ class AttachmentCarousel extends React.Component {
}

/**
* Toggles the visibility of the arrows on mouse hover
* Toggles the visibility of the arrows
* @param {Boolean} showArrows
*/
onShowArrow(showArrows) {
this.setState({showArrows});
}

/**
* Helper to provide a check for touchscreens
*/
onPressShowArrow() {
if (!this.canUseTouchScreen) {
return;
}
this.onShowArrow(!this.state.showArrows);
}

/**
* Helps to navigate between next/previous attachments
* @param {Object} attachmentItem
Expand Down Expand Up @@ -128,6 +117,7 @@ class AttachmentCarousel extends React.Component {
}
return attachmentsAccumulator;
}, []);

const {sourceURL, file} = this.getAttachment(attachments[page]);
this.setState({
page,
Expand Down
22 changes: 10 additions & 12 deletions src/components/AttachmentModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ class AttachmentModal extends PureComponent {
isAttachmentInvalid: false,
attachmentInvalidReasonTitle: null,
attachmentInvalidReason: null,
sourceURL: props.sourceURL,
modalType: CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE,
isConfirmButtonDisabled: false,
confirmButtonFadeAnimation: new Animated.Value(1),
sourceURL: props.isAuthTokenRequired ? addEncryptedAuthTokenToURL(props.sourceURL) : props.sourceURL,
};

this.submitAndClose = this.submitAndClose.bind(this);
Expand All @@ -101,7 +101,7 @@ class AttachmentModal extends PureComponent {
return {
prevIsModalOpen: true,
file: {name: lodashGet(props, 'originalFileName', '')},
sourceURL: lodashGet(props, 'sourceURL', ''),
sourceURL: props.isAuthTokenRequired ? addEncryptedAuthTokenToURL(props.sourceURL) : props.sourceURL,
};
}

Expand Down Expand Up @@ -148,9 +148,10 @@ class AttachmentModal extends PureComponent {
* @returns {Object}
*/
splitExtensionFromFileName(fullFileName) {
const fileName = fullFileName.trim();
const splitFileName = fileName.split('.');
const cleanFileName = fullFileName.trim();
const splitFileName = cleanFileName.split('.');
const fileExtension = splitFileName.pop();
const fileName = splitFileName.shift();
return {fileName, fileExtension};
}

Expand Down Expand Up @@ -261,10 +262,6 @@ class AttachmentModal extends PureComponent {
}

render() {
const sourceURL = this.props.isAuthTokenRequired
? addEncryptedAuthTokenToURL(this.state.sourceURL)
: this.state.sourceURL;

// When the confirm button is visible we don't need bottom padding on the attachment view.
const attachmentViewPaddingStyles = this.props.onConfirm
? [styles.pl5, styles.pr5, styles.pt5]
Expand All @@ -274,7 +271,8 @@ class AttachmentModal extends PureComponent {
? [styles.imageModalImageCenterContainer]
: [styles.imageModalImageCenterContainer, attachmentViewPaddingStyles];

const {fileName, fileExtension} = this.splitExtensionFromFileName(lodashGet(this.state, 'file.name') || this.props.originalFileName);
const originalFileName = lodashGet(this.state, 'file.name') || this.props.originalFileName;
const {fileName, fileExtension} = this.splitExtensionFromFileName(originalFileName);

return (
<>
Expand All @@ -293,7 +291,7 @@ class AttachmentModal extends PureComponent {
title={this.props.headerTitle || this.props.translate('common.attachment')}
shouldShowBorderBottom
shouldShowDownloadButton={this.props.allowDownload}
onDownloadButtonPress={() => fileDownload(sourceURL, this.props.originalFileName)}
onDownloadButtonPress={() => fileDownload(this.state.sourceURL, originalFileName)}
onCloseButtonPress={() => this.setState({isModalOpen: false})}
subtitle={fileName ? (
<TextWithEllipsis
Expand All @@ -310,12 +308,12 @@ class AttachmentModal extends PureComponent {
showArrows={this.state.showArrows}
reportId={this.state.reportId}
onArrowPress={this.onArrowPress}
sourceURL={this.state.sourceURL}
sourceURL={this.props.sourceURL}
/>
) : (this.state.sourceURL
&& (
<AttachmentView
sourceURL={sourceURL}
sourceURL={this.state.sourceURL}
file={this.state.file}
onToggleKeyboard={this.updateConfirmButtonVisibility}
/>
Expand Down
1 change: 1 addition & 0 deletions src/components/AttachmentView.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const propTypes = {

/** Function for native pdf to handle toggling arrows */
onPDFPress: PropTypes.func,

/** Notify parent that the UI should be modified to accommodate keyboard */
onToggleKeyboard: PropTypes.func,

Expand Down
2 changes: 1 addition & 1 deletion src/components/SwipeableView/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const propTypes = {
canSwipeLeft: PropTypes.bool,
canSwipeRight: PropTypes.bool,

/** Callback to facility an press event */
/** Callback to handle a press event because PanResponder will intercept all gestures */
onPress: PropTypes.func,

/** should the movement be animated */
Expand Down

0 comments on commit 59e461c

Please sign in to comment.