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

Migrate CopySelectionHelper.js from class component to hook #22808

Merged
merged 4 commits into from
Jul 18, 2023
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
46 changes: 0 additions & 46 deletions src/components/CopySelectionHelper.js

This file was deleted.

34 changes: 34 additions & 0 deletions src/hooks/useCopySelectionHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {useEffect} from 'react';
import ExpensiMark from 'expensify-common/lib/ExpensiMark';
import CONST from '../CONST';
import KeyboardShortcut from '../libs/KeyboardShortcut';
import Clipboard from '../libs/Clipboard';
import SelectionScraper from '../libs/SelectionScraper';

function copySelectionToClipboard() {
const selection = SelectionScraper.getCurrentSelection();
if (!selection) {
return;
}
const parser = new ExpensiMark();
if (!Clipboard.canSetHtml()) {
Clipboard.setString(parser.htmlToMarkdown(selection));
return;
}
Clipboard.setHtml(selection, parser.htmlToText(selection));
}

export default function useCopySelectionHelper() {
useEffect(() => {
const copyShortcutConfig = CONST.KEYBOARD_SHORTCUTS.COPY;
const unsubscribeCopyShortcut = KeyboardShortcut.subscribe(
copyShortcutConfig.shortcutKey,
copySelectionToClipboard,
copyShortcutConfig.descriptionKey,
copyShortcutConfig.modifiers,
false,
);

return unsubscribeCopyShortcut;
}, []);
}
5 changes: 3 additions & 2 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import Timing from '../../../libs/actions/Timing';
import CONST from '../../../CONST';
import compose from '../../../libs/compose';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import useCopySelectionHelper from '../../../hooks/useCopySelectionHelper';
import useReportScrollManager from '../../../hooks/useReportScrollManager';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import Performance from '../../../libs/Performance';
import {withNetwork} from '../../../components/OnyxProvider';
import FloatingMessageCounter from './FloatingMessageCounter';
import networkPropTypes from '../../../components/networkPropTypes';
import ReportActionsList from './ReportActionsList';
import CopySelectionHelper from '../../../components/CopySelectionHelper';
import * as ReportActionsUtils from '../../../libs/ReportActionsUtils';
import * as ReportUtils from '../../../libs/ReportUtils';
import reportPropTypes from '../../reportPropTypes';
Expand Down Expand Up @@ -61,6 +61,8 @@ const defaultProps = {
function ReportActionsView(props) {
const context = useContext(ReportScreenContext);

useCopySelectionHelper();
jczekalski marked this conversation as resolved.
Show resolved Hide resolved

const reportScrollManager = useReportScrollManager();

const didLayout = useRef(false);
Expand Down Expand Up @@ -340,7 +342,6 @@ function ReportActionsView(props) {
ref={context.reactionListRef}
report={props.report}
/>
<CopySelectionHelper />
</>
);
}
Expand Down