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

Add html formatted comments #64

Merged
merged 4 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions src/components/webView/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {Text} from 'react-native';
import React from 'react';
import PropTypes from 'prop-types';
import ExpensiMark from '../../lib/ExpensiMark';

const parser = new ExpensiMark();
const propTypes = {
html: PropTypes.string,
};
const defaultProps = {
html: '',
};

const WebView = ({html}) => (
<Text>
{/* eslint-disable-next-line react/no-danger */}
<span dangerouslySetInnerHTML={{__html: parser.replace(html)}} />
</Text>
);

WebView.propTypes = propTypes;
WebView.defaultProps = defaultProps;
WebView.displayName = 'WebView';

export default WebView;
22 changes: 22 additions & 0 deletions src/components/webView/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import {Text} from 'react-native';
import Str from '../../lib/Str';
import PropTypes from 'prop-types';

const propTypes = {
html: PropTypes.string,
};
const defaultProps = {
html: '',
};

// @TODO native clients don't support directly injecting HTML so a method needs to be found to do this reliably
const WebView = ({html}) => (
<Text>{Str.htmlDecode(html)}</Text>
);

WebView.propTypes = propTypes;
WebView.defaultProps = defaultProps;
WebView.displayName = 'WebView';

export default WebView;
5 changes: 4 additions & 1 deletion src/page/HomePage/Report/ReportHistoryItemFragment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import {Text} from 'react-native';
import WebView from '../../../components/webView';
import Str from '../../../lib/Str';
import ReportHistoryFragmentPropTypes from './ReportHistoryFragmentPropTypes';
import styles from '../../../style/StyleSheet';
Expand All @@ -12,7 +13,9 @@ const propTypes = {
const ReportHistoryItemFragment = ({fragment}) => {
switch (fragment.type) {
case 'COMMENT':
return <Text>{Str.htmlDecode(fragment.text)}</Text>;
return fragment.html
? <WebView html={fragment.html} />
: <Text>{Str.htmlDecode(fragment.text)}</Text>;

// return fragment.html
// ? (
Expand Down