Skip to content

Commit

Permalink
feat : wimdow.Mobile 함수 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
PenguinKKIM committed Oct 9, 2024
1 parent 3f39a4d commit 6ee4620
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 3 deletions.
18 changes: 17 additions & 1 deletion components/ClickSpeedTestGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,22 @@ export default function ClickSpeedTest({ onClose }: { onClose: () => void }) {
const finalResult = clicks / 10;
setResult(finalResult);
if (finalResult >= 5 && !hasMutated) {
// 성공 시 모바일로 알림 전송
if (
typeof window !== 'undefined' &&
window.Mobile &&
typeof window.Mobile.sendToMobile === 'function'
) {
window.Mobile.sendToMobile(true);
}
// mutate();
setHasMutated(true);
} else if (!hasMutated) {
setGameFailed(true);
}
}
return () => clearInterval(timer);
}, [gameStarted, timeLeft, hasMutated]);
}, [gameStarted, timeLeft, hasMutated, clicks]);

const startGame = () => {
setClicks(0);
Expand All @@ -47,6 +55,14 @@ export default function ClickSpeedTest({ onClose }: { onClose: () => void }) {
};

const handleCloseModal = () => {
if (
typeof window !== 'undefined' &&
window.Mobile &&
typeof window.Mobile.sendCancel === 'function'
) {
// 닫기 시 모바일에 취소 알림 전송
window.Mobile.sendCancel();
}
onClose();
};

Expand Down
24 changes: 23 additions & 1 deletion components/MemoryCardGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ export default function MemoryCardGame({ onClose }: { onClose: () => void }) {
if (matchedPairs.length + 1 === symbols.length) {
alert('앱 심사중으로 쿠폰이 발급되질 않습니다! 심사후에 이용해주세요!');
setGameOver(true);

// 성공 시 모바일로 알림 전송
if (
typeof window !== 'undefined' &&
window.Mobile &&
typeof window.Mobile.sendToMobile === 'function'
) {
window.Mobile.sendToMobile(true);
}

// mutate();
}
} else {
Expand All @@ -58,6 +68,14 @@ export default function MemoryCardGame({ onClose }: { onClose: () => void }) {
};

const handleCloseModal = () => {
if (
typeof window !== 'undefined' &&
window.Mobile &&
typeof window.Mobile.sendCancel === 'function'
) {
// 닫기 시 모바일에 취소 알림 전송
window.Mobile.sendCancel();
}
onClose();
};

Expand All @@ -77,7 +95,11 @@ export default function MemoryCardGame({ onClose }: { onClose: () => void }) {
{cards.map((card, index) => (
<div
key={card.id}
className={`h-16 flex items-center justify-center text-2xl cursor-pointer ${flippedIndexes.includes(index) || matchedPairs.includes(card.symbol) ? 'bg-blue-200' : 'bg-gray-300'}`}
className={`h-16 flex items-center justify-center text-2xl cursor-pointer ${
flippedIndexes.includes(index) || matchedPairs.includes(card.symbol)
? 'bg-blue-200'
: 'bg-gray-300'
}`}
onClick={() => handleCardClick(index)}
>
{flippedIndexes.includes(index) || matchedPairs.includes(card.symbol)
Expand Down
14 changes: 14 additions & 0 deletions components/MovingGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export default function MovingGame({ onClose }: { onClose: () => void }) {

useEffect(() => {
if (score >= 5) {
if (
typeof window !== 'undefined' &&
window.Mobile &&
typeof window.Mobile.sendToMobile === 'function'
) {
window.Mobile.sendToMobile(true);
}
alert('앱 심사중으로 쿠폰이 발급되질 않습니다! 심사후에 이용해주세요!');
onClose();
}
Expand Down Expand Up @@ -141,6 +148,13 @@ export default function MovingGame({ onClose }: { onClose: () => void }) {
}, []);

const handleCloseModal = () => {
if (
typeof window !== 'undefined' &&
window.Mobile &&
typeof window.Mobile.sendCancel === 'function'
) {
window.Mobile.sendCancel();
}
onClose();
};

Expand Down
18 changes: 18 additions & 0 deletions components/NumberBaseballGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export default function NumberBaseballGame({ onClose }: { onClose: () => void })
setMessage(`축하합니다! ${attempts + 1}번 만에 맞췄습니다.`);
alert('앱 심사중으로 쿠폰이 발급되질 않습니다! 심사후에 이용해주세요!');
setGameOver(true);

// 모바일에 성공 알림 전송
if (
typeof window !== 'undefined' &&
window.Mobile &&
typeof window.Mobile.sendToMobile === 'function'
) {
window.Mobile.sendToMobile(true);
}

// mutate(); // 티켓 지급
} else {
setMessage(`${strikes} 스트라이크, ${balls} 볼`);
Expand All @@ -79,6 +89,14 @@ export default function NumberBaseballGame({ onClose }: { onClose: () => void })
};

const handleCloseModal = () => {
if (
typeof window !== 'undefined' &&
window.Mobile &&
typeof window.Mobile.sendCancel === 'function'
) {
// 모바일에 취소 알림 전송
window.Mobile.sendCancel();
}
onClose();
};

Expand Down
20 changes: 19 additions & 1 deletion components/NumberGuessingGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ export default function NumberGuessingGame({ onClose }: { onClose: () => void })
setMessage(`축하합니다. ${attempts + 1}번 만에 맞추셨습니다.`);
alert('앱 심사중으로 쿠폰이 발급되질 않습니다! 심사후에 이용해주세요!');
setGameOver(true);
// mutate();

// 성공 시 모바일에 알림 전송
if (
typeof window !== 'undefined' &&
window.Mobile &&
typeof window.Mobile.sendToMobile === 'function'
) {
window.Mobile.sendToMobile(true);
}

// mutate(); // 티켓 지급
} else if (guessNumber < targetNumber) {
setMessage('더 큰 숫자를 입력해보세요.');
} else {
Expand All @@ -48,6 +58,14 @@ export default function NumberGuessingGame({ onClose }: { onClose: () => void })
};

const handleCloseModal = () => {
if (
typeof window !== 'undefined' &&
window.Mobile &&
typeof window.Mobile.sendCancel === 'function'
) {
// 닫기 시 모바일에 취소 알림 전송
window.Mobile.sendCancel();
}
onClose();
handleResetGame();
};
Expand Down
10 changes: 10 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export {};

declare global {
interface Window {
Mobile?: {
sendCancel: () => void;
sendToMobile: (status: boolean) => void;
};
}
}

0 comments on commit 6ee4620

Please sign in to comment.