-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Change UI view for Attachments in Chat #4736
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
Changes from 6 commits
2e2b39f
7c57fc9
9b6706c
7b52c25
622fef0
924271f
f658da2
cab465c
5518ed2
ef75235
17b84d6
dae136d
1929de1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import React from 'react'; | ||
import {StyleSheet} from 'react-native'; | ||
import {Pressable, StyleSheet} from 'react-native'; | ||
import lodashGet from 'lodash/get'; | ||
import Text from '../../Text'; | ||
import Icon from '../../Icon'; | ||
import {propTypes, defaultProps} from '../anchorForCommentsOnlyPropTypes'; | ||
import PressableWithSecondaryInteraction from '../../PressableWithSecondaryInteraction'; | ||
import {showContextMenu} from '../../../pages/home/report/ContextMenu/ReportActionContextMenu'; | ||
import {CONTEXT_MENU_TYPES} from '../../../pages/home/report/ContextMenu/ContextMenuActions'; | ||
import {Download} from '../../Icon/Expensicons'; | ||
import AttachmentView from '../../AttachmentView'; | ||
import fileDownload from '../../../libs/fileDownload'; | ||
|
||
|
||
/* | ||
|
@@ -17,34 +21,54 @@ const BaseAnchorForCommentsOnly = ({ | |
target, | ||
children, | ||
style, | ||
text, | ||
...props | ||
}) => { | ||
let linkRef; | ||
return ( | ||
<PressableWithSecondaryInteraction | ||
onSecondaryInteraction={ | ||
(event) => { | ||
showContextMenu( | ||
CONTEXT_MENU_TYPES.LINK, | ||
event, | ||
href, | ||
lodashGet(linkRef, 'current'), | ||
); | ||
} | ||
} | ||
> | ||
<Text | ||
ref={el => linkRef = el} | ||
style={StyleSheet.flatten(style)} | ||
accessibilityRole="link" | ||
href={href} | ||
hrefAttrs={{rel, target}} | ||
|
||
props.shouldDownloadFile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update prop name to isAttachment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
? ( | ||
<Pressable onPress={() => { | ||
fileDownload(href); | ||
}} | ||
> | ||
<AttachmentView | ||
sourceURL={href} | ||
file={{name: text}} | ||
rightElement={( | ||
<Icon src={Download} /> | ||
)} | ||
/> | ||
</Pressable> | ||
) | ||
: ( | ||
<PressableWithSecondaryInteraction | ||
onSecondaryInteraction={ | ||
(event) => { | ||
showContextMenu( | ||
CONTEXT_MENU_TYPES.LINK, | ||
event, | ||
href, | ||
lodashGet(linkRef, 'current'), | ||
); | ||
} | ||
} | ||
> | ||
<Text | ||
ref={el => linkRef = el} | ||
style={StyleSheet.flatten(style)} | ||
accessibilityRole="link" | ||
href={href} | ||
hrefAttrs={{rel, target}} | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
> | ||
{children} | ||
</Text> | ||
</PressableWithSecondaryInteraction> | ||
{...props} | ||
> | ||
{children} | ||
</Text> | ||
</PressableWithSecondaryInteraction> | ||
) | ||
|
||
); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ const propTypes = { | |
/** Any additional styles to apply */ | ||
// eslint-disable-next-line react/forbid-prop-types | ||
style: PropTypes.any, | ||
|
||
text: PropTypes.string, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this prop above style, and add comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
}; | ||
|
||
const defaultProps = { | ||
|
@@ -33,6 +35,7 @@ const defaultProps = { | |
shouldDownloadFile: false, | ||
children: null, | ||
style: {}, | ||
text: '', | ||
}; | ||
|
||
export {propTypes, defaultProps}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,13 +20,16 @@ const propTypes = { | |
name: PropTypes.string, | ||
}), | ||
|
||
rightElement: PropTypes.element, | ||
|
||
...withLocalizePropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
file: { | ||
name: '', | ||
}, | ||
rightElement: undefined, | ||
}; | ||
|
||
const AttachmentView = (props) => { | ||
|
@@ -58,6 +61,11 @@ const AttachmentView = (props) => { | |
<Icon src={Paperclip} /> | ||
</View> | ||
<Text style={[styles.textStrong]}>{props.file && props.file.name}</Text> | ||
{props.rightElement && ( | ||
<View style={styles.ml2}> | ||
{props.rightElement} | ||
</View> | ||
)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of passing down rightElement as props, pass down a prop called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
</View> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import { | |
splitBoxModelStyle, | ||
} from 'react-native-render-html'; | ||
import PropTypes from 'prop-types'; | ||
import lodashGet from 'lodash/get'; | ||
import Config from '../../CONFIG'; | ||
import styles, {webViewStyles, getFontFamilyMonospace} from '../../styles/styles'; | ||
import fontFamily from '../../styles/fontFamily'; | ||
|
@@ -67,6 +68,8 @@ function AnchorRenderer({tnode, key, style}) { | |
|
||
// An auth token is needed to download Expensify chat attachments | ||
const isAttachment = Boolean(htmlAttribs['data-expensify-source']); | ||
const fileName = isAttachment ? lodashGet(tnode, 'domNode.children[0].data') : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a default param to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
return ( | ||
<AnchorForCommentsOnly | ||
href={htmlAttribs.href} | ||
|
@@ -81,6 +84,7 @@ function AnchorRenderer({tnode, key, style}) { | |
rel={htmlAttribs.rel || 'noopener noreferrer'} | ||
style={style} | ||
key={key} | ||
text={fileName} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like above, change text prop name to fileName There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
> | ||
<TNodeChildrenRenderer tnode={tnode} /> | ||
</AnchorForCommentsOnly> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's update this prop to isAttachment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done