Skip to content

Commit

Permalink
fix: http에서 클립보드 api 사용 못해서 발생하는 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
minani-0621 committed Aug 23, 2024
1 parent 011fea8 commit a2e57bb
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 35 deletions.
53 changes: 36 additions & 17 deletions Caecae/src/components/RacingGame/RacingGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,44 @@ const RacingGame: React.FC = () => {
const baseShareUrl = "http://www.caecae.kro.kr/a/"
const shareUrl = baseShareUrl + shortUrl;

navigator.clipboard.writeText(shareUrl)
.then(() => {
setShowMessage(true);

let textArea = document.createElement("textarea");
textArea.value = shareUrl;

textArea.style.position = "fixed";
textArea.style.left = "-9999px";
textArea.style.top = "-9999px";

document.body.appendChild(textArea);
textArea.select();

return new Promise((res, rej) => {
if (document.execCommand('copy')) {
res(shareUrl)
}else {
rej();
}
textArea.remove();
}).then(() => {
setShowMessage(true);

setTimeout(() => {
setAnimate(true);

setTimeout(() => {
setAnimate(true);
setAnimate(false);

setTimeout(() => {
setAnimate(false);

setTimeout(() => {
setShowMessage(false);
setIsAnimating(false);
}, 500);

}, 3000);
}, 10);
});
setShowMessage(false);
setIsAnimating(false);
}, 500);

}, 3000);

}, 10);
}).catch((error) => {
console.error("클립보드 복사 실패:", error);
setIsAnimating(false);
});
}catch(error) {
console.error("단축 Url api 호출 실패:", error);
}
Expand Down
39 changes: 39 additions & 0 deletions Caecae/src/features/FindingGameLanding/LadingPageTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,45 @@ const LadingPageTitle = ({ onClick }: LadingPageTitleProps) => {
setIsAnimating(true);
const url: string = window.location.href;

let textArea = document.createElement("textarea");
textArea.value = url;

textArea.style.position = "fixed";
textArea.style.left = "-9999px";
textArea.style.top = "-9999px";

document.body.appendChild(textArea);
textArea.select();

return new Promise((res, rej) => {
if (document.execCommand('copy')) {
res(url)
}else {
rej();
}
textArea.remove();
}).then(() => {
setShowMessage(true);

setTimeout(() => {
setAnimate(true);

setTimeout(() => {
setAnimate(false);

setTimeout(() => {
setShowMessage(false);
setIsAnimating(false);
}, 500);

}, 3000);

}, 10);
}).catch((err: Error) => {
console.error('URL 복사에 실패했습니다.', err);
setIsAnimating(false);
});

navigator.clipboard
.writeText(url)
.then(() => {
Expand Down
51 changes: 33 additions & 18 deletions Caecae/src/features/RacingGameLanding/EventIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,44 @@ const EventIntro: React.FC<EventIntroProps> = ({isEventOpen}) => {
setIsAnimating(true);
const url: string = window.location.href;

navigator.clipboard.writeText(url)
.then(() => {
setShowMessage(true);
let textArea = document.createElement("textarea");
textArea.value = url;

textArea.style.position = "fixed";
textArea.style.left = "-9999px";
textArea.style.top = "-9999px";

document.body.appendChild(textArea);
textArea.select();

return new Promise((res, rej) => {
if (document.execCommand('copy')) {
res(url)
}else {
rej();
}
textArea.remove();
}).then(() => {
setShowMessage(true);

setTimeout(() => {
setAnimate(true);

setTimeout(() => {
setAnimate(true);
setAnimate(false);

setTimeout(() => {
setAnimate(false);

setTimeout(() => {
setShowMessage(false);
setIsAnimating(false);
}, 500);
setShowMessage(false);
setIsAnimating(false);
}, 500);

}, 3000);

}, 10);
})
.catch((err: Error) => {
console.error('URL 복사에 실패했습니다.', err);
setIsAnimating(false);
});
}, 3000);

}, 10);
}).catch((err: Error) => {
console.error('URL 복사에 실패했습니다.', err);
setIsAnimating(false);
});
};

const checkEventOpen = () => {
Expand Down

0 comments on commit a2e57bb

Please sign in to comment.