Skip to content

Commit

Permalink
Merge pull request #97 from Devminjeong-eum/fix/DEV-133
Browse files Browse the repository at this point in the history
fix: URL 공유 모달 뜰 때, 한번 더 클릭 시 없어지도록 변경
  • Loading branch information
nyoung113 authored Jun 30, 2024
2 parents 82e08c2 + de11d57 commit beef363
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
13 changes: 11 additions & 2 deletions src/components/common/CopiedNotice.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import CheckSvg from '@/components/svg-component/CheckSvg.tsx';

export function CopiedNotice() {
interface Props {
isOpen: boolean;
handleClose: () => void;
}
export function CopiedNotice({ isOpen, handleClose }: Props) {
if (!isOpen) return null;

return (
<div className="w-screen h-screen fixed left-0 top-0 flex justify-center items-center z-10">
<div
className="w-screen h-screen fixed left-0 top-0 flex justify-center items-center z-10"
onClick={handleClose}
>
<div className="w-full h-screen flex justify-center items-center max-w-[430px] bg-[#000000] opacity-70 mix-blend-multiply" />
<div className="absolute flex gap-1.5 py-4 px-[22px] rounded-[16px] bg-[#05050555]">
<CheckSvg />
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/ShareModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function ShareModal() {
const { handleShare } = useLoadKakaoScript();
const router = useRouter();
const shareURL = window.location.href;
const { isCopied, onCopyClipboard } = useCopyClipboard({
const { isCopied, onCopyClipboard, onCloseCopyClipboard } = useCopyClipboard({
url: shareURL,
});

Expand Down Expand Up @@ -44,7 +44,7 @@ export default function ShareModal() {
</div>
</div>
</div>
{isCopied && <CopiedNotice />}
<CopiedNotice isOpen={isCopied} handleClose={onCloseCopyClipboard} />
</div>
);
}
7 changes: 4 additions & 3 deletions src/components/pages/detail/URLShareButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import useCopyClipboard from '@/hooks/useCopyClipboard.ts';
import { CopiedNotice } from '@/components/common/CopiedNotice.tsx';

export default function URLShareButton() {
const { isCopied, onCopyClipboard } = useCopyClipboard();
const { isCopied, onCopyClipboard, onCloseCopyClipboard } =
useCopyClipboard();

return (
<div>
<button onClick={() => onCopyClipboard()}>
<button onClick={onCopyClipboard}>
<ExternalSvg />
</button>
{isCopied && <CopiedNotice />}
{<CopiedNotice isOpen={isCopied} handleClose={onCloseCopyClipboard} />}
</div>
);
}
12 changes: 8 additions & 4 deletions src/hooks/useCopyClipboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';

async function copyURL(url?: string) {
const targetUrl = url ? url : window.document.location.href;
Expand Down Expand Up @@ -28,10 +28,14 @@ export default function useCopyClipboard(props?: Props) {
};
}, [isCopied, props?.ms]);

const onCopyClipboard = async () => {
const onCopyClipboard = useCallback(async () => {
await copyURL(props?.url);
setIsCopied(true);
};
}, [props?.url]);

return { isCopied, onCopyClipboard };
const onCloseCopyClipboard = useCallback(() => {
setIsCopied(false);
}, []);

return { isCopied, setIsCopied, onCopyClipboard, onCloseCopyClipboard };
}

0 comments on commit beef363

Please sign in to comment.