Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
parasharrajat committed Apr 1, 2021
1 parent 4a4481d commit 002e5c1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
1 change: 0 additions & 1 deletion config/webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ const webpackConfig = {
alias: {
'react-native-config': 'react-web-config',
'react-native$': 'react-native-web',
'@react-native-community/clipboard': 'react-native-web',
},

// React Native libraries may have web-specific module implementations that appear with the extension `.web.js`
Expand Down
5 changes: 2 additions & 3 deletions src/libs/Clipboard/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// on Web/desktop this import will be replaced with `react-native-web` so we have to import the named export;
// according to the `react-native-web`;
import {Clipboard} from '@react-native-community/clipboard';
// on Web/desktop this import will be replaced with `react-native-web`
import {Clipboard} from 'react-native-web';

export default Clipboard;
17 changes: 16 additions & 1 deletion src/libs/reportUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from 'underscore';
import Str from 'expensify-common/lib/str';
import lodashGet from 'lodash/get';

/**
* Returns the concatenated title for the PrimaryLogins of a report
Expand All @@ -11,7 +12,21 @@ function getReportParticipantsTitle(logins) {
return _.map(logins, login => Str.removeSMSDomain(login)).join(', ');
}

/**
* Check whether a report action is Attachment is not.
*
* @param {Object} reportAction action from a Report
* @returns {Boolean}
*/
function isReportActionAttachment(reportAction) {
if (_.has(reportAction, 'isAttachment')) {
return reportAction.isAttachment;
}
const lastMessage = _.last(lodashGet(reportAction, 'message', null));
return lodashGet(lastMessage, 'text', '') === '[Attachment]';
}

export {
// eslint-disable-next-line import/prefer-default-export
getReportParticipantsTitle,
isReportActionAttachment,
};
13 changes: 6 additions & 7 deletions src/pages/home/report/ReportActionContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import getReportActionContextMenuStyles from '../../../styles/getReportActionCon
import ReportActionContextMenuItem from './ReportActionContextMenuItem';
import ReportActionPropTypes from './ReportActionPropTypes';
import Clipboard from '../../../libs/Clipboard';
import {isReportActionAttachment} from '../../../libs/reportUtils';

/**
* A list of all the context actions in this menu.
Expand All @@ -29,42 +30,40 @@ const CONTEXT_ACTIONS = [
const lastMessage = _.last(lodashGet(action, 'message', null));
const html = lodashGet(lastMessage, 'html', '');
const text = lodashGet(lastMessage, 'text', '');
const isAttachment = text === '[Attachment]';
if (!isAttachment) {
if (!isReportActionAttachment(action)) {
Clipboard.setString(text);
} else {
Clipboard.setString(html);
}
return true;
},
},

// Copy chat link
{
text: 'Copy Link',
icon: LinkCopy,
onPress: () => { },
onPress: () => {},
},

// Mark as Unread
{
text: 'Mark as Unread',
icon: Mail,
onPress: () => { },
onPress: () => {},
},

// Edit Comment
{
text: 'Edit Comment',
icon: Pencil,
onPress: () => { },
onPress: () => {},
},

// Delete Comment
{
text: 'Delete Comment',
icon: Trashcan,
onPress: () => { },
onPress: () => {},
},
];

Expand Down
17 changes: 9 additions & 8 deletions src/pages/home/report/ReportActionContextMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,21 @@ class ReportActionContextMenuItem extends Component {
this.state = {
success: false,
};
this.onPress = this.onPress.bind(this);
this.triggerPressAndUpdateSuccess = this.triggerPressAndUpdateSuccess.bind(this);
}

/**
* Called on button press and mark the run
*
* @memberof ReportActionContextMenuItem
*/
onPress() {
triggerPressAndUpdateSuccess() {
if (this.state.success) {
return;
}
const pressResult = this.props.onPress();
if (pressResult) {
this.props.onPress();

// We only set the success state when we have icon or text to represent the success state
// We may want to replace this check by checking the Result from OnPress Callback in future.
if (this.props.successIcon || this.props.successText) {
this.setState({
success: true,
});
Expand All @@ -81,7 +82,7 @@ class ReportActionContextMenuItem extends Component {
? (
<Tooltip text={text}>
<Pressable
onPress={this.onPress}
onPress={this.triggerPressAndUpdateSuccess}
style={
({hovered, pressed}) => getButtonStyle(
getButtonState(hovered, pressed, this.state.success),
Expand All @@ -98,7 +99,7 @@ class ReportActionContextMenuItem extends Component {
</Tooltip>
) : (
<Pressable
onPress={this.onPress}
onPress={this.triggerPressAndUpdateSuccess}
style={
({hovered, pressed}) => getButtonStyle(
getButtonState(hovered, pressed, this.state.success),
Expand Down

0 comments on commit 002e5c1

Please sign in to comment.