Skip to content

Commit

Permalink
[#3] feat: toggleModal => openModal, closeModal. 적절한 event delegation 위해
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbin9775 committed Aug 7, 2021
1 parent 85e9385 commit bc341cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/common/ModalContainer/ModalContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import styled from 'styled-components';
type Props = {
isPopup?: boolean;
contentComponent?: React.ReactNode;
onClickOverlay?: () => void;
onClickOverlay?: (e: React.MouseEvent<HTMLElement>) => void;
};

const ModalContainer = ({
Expand All @@ -14,7 +14,7 @@ const ModalContainer = ({
}: Props) => {
const onClickOnlyOverlay = (e: React.MouseEvent<HTMLElement>) => {
if (e.target !== e.currentTarget) return;
if (onClickOverlay) onClickOverlay();
if (onClickOverlay) onClickOverlay(e);
};

return isPopup ? (
Expand Down
16 changes: 12 additions & 4 deletions src/components/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,26 @@ const Main = () => {
const rVideos = videos.filter((video) => video.rank % 2 !== 0);
const [isModalOpen, setModalOpen] = useState(false);

const toggleModal = () => {
setModalOpen((prev) => !prev);
const openModal = (e: React.MouseEvent<HTMLElement>) => {
const targetElement = e.target as HTMLElement;
if (targetElement.tagName === 'VIDEO') {
setModalOpen(true);
}
};

const closeModal = (e: React.MouseEvent<HTMLElement>) => {
setModalOpen(false);
};

return (
<div style={{ width: '65%', margin: 'auto' }}>
<VideoSelectBar popularTags={datas.popularTags} />
<ModalContainer
isPopup={isModalOpen}
onClickOverlay={toggleModal}
onClickOverlay={closeModal}
contentComponent={<VideoModal />}
/>
<VideoWrapper onClick={toggleModal}>
<VideoWrapper onClick={openModal}>
<div>
{lVideos.map((data) => (
<LazyItem
Expand Down

0 comments on commit bc341cc

Please sign in to comment.