mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-12 02:23:49 +00:00
Removed duplicated code by creating a helper function
This commit is contained in:
@@ -6,10 +6,9 @@ import { CopyToClipboard } from 'react-copy-to-clipboard';
|
||||
import { Card, CardBody, Tooltip } from 'reactstrap';
|
||||
import PropTypes from 'prop-types';
|
||||
import { createShortUrlResultType } from '../reducers/shortUrlCreationResult';
|
||||
import { stateFlagTimeout } from '../../utils/utils';
|
||||
import './CreateShortUrlResult.scss';
|
||||
|
||||
const TIME_TO_SHOW_COPY_TOOLTIP = 2000;
|
||||
|
||||
const propTypes = {
|
||||
resetCreateShortUrl: PropTypes.func,
|
||||
error: PropTypes.bool,
|
||||
@@ -38,10 +37,7 @@ export default class CreateShortUrlResult extends React.Component {
|
||||
}
|
||||
|
||||
const { shortUrl } = result;
|
||||
const onCopy = () => {
|
||||
this.setState({ showCopyTooltip: true });
|
||||
setTimeout(() => this.setState({ showCopyTooltip: false }), TIME_TO_SHOW_COPY_TOOLTIP);
|
||||
};
|
||||
const onCopy = () => stateFlagTimeout(this.setState.bind(this), 'showCopyTooltip');
|
||||
|
||||
return (
|
||||
<Card inverse className="bg-main mt-3">
|
||||
|
||||
@@ -7,11 +7,10 @@ import { shortUrlsListParamsType } from '../reducers/shortUrlsListParams';
|
||||
import { serverType } from '../../servers/prop-types';
|
||||
import ExternalLink from '../../utils/ExternalLink';
|
||||
import { shortUrlType } from '../reducers/shortUrlsList';
|
||||
import { stateFlagTimeout } from '../../utils/utils';
|
||||
import { ShortUrlsRowMenu } from './ShortUrlsRowMenu';
|
||||
import './ShortUrlsRow.scss';
|
||||
|
||||
const COPIED_MSG_TIME = 2000;
|
||||
|
||||
const propTypes = {
|
||||
refreshList: PropTypes.func,
|
||||
shortUrlsListParams: shortUrlsListParamsType,
|
||||
@@ -67,10 +66,7 @@ export class ShortUrlsRow extends React.Component {
|
||||
completeShortUrl={completeShortUrl}
|
||||
selectedServer={selectedServer}
|
||||
shortUrl={shortUrl}
|
||||
onCopyToClipboard={() => {
|
||||
this.setState({ copiedToClipboard: true });
|
||||
setTimeout(() => this.setState({ copiedToClipboard: false }), COPIED_MSG_TIME);
|
||||
}}
|
||||
onCopyToClipboard={() => stateFlagTimeout(this.setState.bind(this), 'copiedToClipboard')}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user