Skip to content

Commit

Permalink
Apply useModalClose to collection ShareURL.
Browse files Browse the repository at this point in the history
  • Loading branch information
lindapaiste committed Jul 16, 2023
1 parent 0854d43 commit 6582362
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions client/modules/User/components/Collection.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PropTypes from 'prop-types';
import React, { useState, useRef, useEffect } from 'react';
import React, { useState, useCallback } from 'react';
import { Helmet } from 'react-helmet';
import { connect } from 'react-redux';
import { Link } from 'react-router';
Expand All @@ -9,6 +9,7 @@ import classNames from 'classnames';

import Button from '../../../common/Button';
import { DropdownArrowIcon } from '../../../common/icons';
import useModalClose from '../../../common/useModalClose';
import * as ProjectActions from '../../IDE/actions/project';
import * as ProjectsActions from '../../IDE/actions/projects';
import * as CollectionsActions from '../../IDE/actions/collections';
Expand All @@ -30,30 +31,12 @@ import RemoveIcon from '../../../images/close.svg';

const ShareURL = ({ value }) => {
const [showURL, setShowURL] = useState(false);
const node = useRef();
const { t } = useTranslation();

const handleClickOutside = (e) => {
if (node.current.contains(e.target)) {
return;
}
setShowURL(false);
};

useEffect(() => {
if (showURL) {
document.addEventListener('mousedown', handleClickOutside);
} else {
document.removeEventListener('mousedown', handleClickOutside);
}

return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, [showURL]);
const close = useCallback(() => setShowURL(false), [setShowURL]);
const ref = useModalClose(close);

return (
<div className="collection-share" ref={node}>
<div className="collection-share" ref={ref}>
<Button
onClick={() => setShowURL(!showURL)}
iconAfter={<DropdownArrowIcon />}
Expand Down

0 comments on commit 6582362

Please sign in to comment.