mirror of
https://github.com/HugeFrog24/shakethefrog.git
synced 2026-05-01 07:02:18 +00:00
Update deps
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useFeature } from '../../../providers/FeatureProvider';
|
||||
|
||||
export default function CheckoutCancelPage() {
|
||||
const router = useRouter();
|
||||
const t = useTranslations('ui');
|
||||
const paymentsEnabled = useFeature('paymentsEnabled');
|
||||
const [countdown, setCountdown] = useState(5);
|
||||
|
||||
// Redirect home immediately if payments are disabled
|
||||
useEffect(() => {
|
||||
if (!paymentsEnabled) {
|
||||
router.replace('/');
|
||||
}
|
||||
}, [paymentsEnabled, router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!paymentsEnabled) return;
|
||||
|
||||
// Countdown timer to redirect to home
|
||||
const timer = setInterval(() => {
|
||||
setCountdown((prev) => {
|
||||
if (prev <= 1) {
|
||||
clearInterval(timer);
|
||||
router.push('/');
|
||||
return 0;
|
||||
}
|
||||
return prev - 1;
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
return () => clearInterval(timer);
|
||||
}, [router, paymentsEnabled]);
|
||||
|
||||
if (!paymentsEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleGoBack = () => {
|
||||
router.push('/');
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 flex items-center justify-center p-4">
|
||||
<div className="max-w-md w-full bg-white dark:bg-gray-800 rounded-lg shadow-xl p-8 text-center">
|
||||
{/* Cancel Icon */}
|
||||
<div className="w-16 h-16 mx-auto mb-6 bg-gray-100 dark:bg-gray-700 rounded-full flex items-center justify-center">
|
||||
<svg className="w-8 h-8 text-gray-600 dark:text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
{/* Cancel Message */}
|
||||
<h1 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
|
||||
{t('checkout.cancel.title')}
|
||||
</h1>
|
||||
|
||||
<p className="text-gray-600 dark:text-gray-300 mb-6">
|
||||
{t('checkout.cancel.message')}
|
||||
</p>
|
||||
|
||||
<p className="text-gray-500 dark:text-gray-400 mb-6">
|
||||
{t('checkout.cancel.tryAgain')}
|
||||
</p>
|
||||
|
||||
{/* Action Buttons */}
|
||||
<div className="space-y-3">
|
||||
<button
|
||||
onClick={handleGoBack}
|
||||
className="w-full px-6 py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors font-medium"
|
||||
>
|
||||
{t('checkout.cancel.backToApp')}
|
||||
</button>
|
||||
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400">
|
||||
{t('checkout.cancel.redirecting', { countdown })}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Help Info */}
|
||||
<div className="mt-8 pt-6 border-t border-gray-200 dark:border-gray-700">
|
||||
<p className="text-xs text-gray-500 dark:text-gray-400">
|
||||
{t('checkout.cancel.needHelp')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useSearchParams, useRouter } from 'next/navigation';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { appConfig } from '../../../config/app';
|
||||
import { SkinId } from '../../../types';
|
||||
import { useLocalizedSkinName } from '../../../hooks/useLocalizedSkinName';
|
||||
import { useFeature } from '../../../providers/FeatureProvider';
|
||||
|
||||
export default function CheckoutSuccessPage() {
|
||||
const searchParams = useSearchParams();
|
||||
const router = useRouter();
|
||||
const t = useTranslations('ui');
|
||||
const getLocalizedSkinName = useLocalizedSkinName();
|
||||
const paymentsEnabled = useFeature('paymentsEnabled');
|
||||
const [countdown, setCountdown] = useState(5);
|
||||
|
||||
const skinId = searchParams.get('skin') as SkinId;
|
||||
const skin = skinId ? appConfig.skins[skinId] : null;
|
||||
const skinName = skinId ? getLocalizedSkinName(skinId) : '';
|
||||
|
||||
// Redirect home immediately if payments are disabled
|
||||
useEffect(() => {
|
||||
if (!paymentsEnabled) {
|
||||
router.replace('/');
|
||||
}
|
||||
}, [paymentsEnabled, router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!paymentsEnabled) return;
|
||||
|
||||
// Countdown timer to redirect to home
|
||||
const timer = setInterval(() => {
|
||||
setCountdown((prev) => {
|
||||
if (prev <= 1) {
|
||||
clearInterval(timer);
|
||||
// Redirect to home with the purchased skin
|
||||
const params = new URLSearchParams();
|
||||
if (skinId && skinId !== appConfig.defaultSkin) {
|
||||
params.set('skin', skinId);
|
||||
}
|
||||
const newUrl = `/${params.toString() ? '?' + params.toString() : ''}`;
|
||||
router.push(newUrl);
|
||||
return 0;
|
||||
}
|
||||
return prev - 1;
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
return () => clearInterval(timer);
|
||||
}, [skinId, router, paymentsEnabled]);
|
||||
|
||||
if (!paymentsEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleGoToApp = () => {
|
||||
const params = new URLSearchParams();
|
||||
if (skinId && skinId !== appConfig.defaultSkin) {
|
||||
params.set('skin', skinId);
|
||||
}
|
||||
const newUrl = `/${params.toString() ? '?' + params.toString() : ''}`;
|
||||
router.push(newUrl);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-green-50 to-blue-50 dark:from-gray-900 dark:to-gray-800 flex items-center justify-center p-4">
|
||||
<div className="max-w-md w-full bg-white dark:bg-gray-800 rounded-lg shadow-xl p-8 text-center">
|
||||
{/* Success Icon */}
|
||||
<div className="w-16 h-16 mx-auto mb-6 bg-green-100 dark:bg-green-900 rounded-full flex items-center justify-center">
|
||||
<svg className="w-8 h-8 text-green-600 dark:text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
{/* Success Message */}
|
||||
<h1 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
|
||||
{t('checkout.success.title')}
|
||||
</h1>
|
||||
|
||||
{skin && (
|
||||
<div className="mb-6">
|
||||
<div className="w-20 h-20 mx-auto mb-4 bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center">
|
||||
<img
|
||||
src={skin.normal}
|
||||
alt={skinName}
|
||||
className="w-16 h-16"
|
||||
/>
|
||||
</div>
|
||||
<p className="text-gray-600 dark:text-gray-300">
|
||||
{t('checkout.success.unlockedSkin', { skinName })}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<p className="text-gray-500 dark:text-gray-400 mb-6">
|
||||
{t('checkout.success.thankYou')}
|
||||
</p>
|
||||
|
||||
{/* Action Buttons */}
|
||||
<div className="space-y-3">
|
||||
<button
|
||||
onClick={handleGoToApp}
|
||||
className="w-full px-6 py-3 bg-green-600 hover:bg-green-700 text-white rounded-lg transition-colors font-medium"
|
||||
>
|
||||
{t('checkout.success.goToApp')}
|
||||
</button>
|
||||
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400">
|
||||
{t('checkout.success.redirecting', { countdown })}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Receipt Info */}
|
||||
<div className="mt-8 pt-6 border-t border-gray-200 dark:border-gray-700">
|
||||
<p className="text-xs text-gray-500 dark:text-gray-400">
|
||||
{t('checkout.success.receiptSent')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { NextIntlClientProvider } from 'next-intl';
|
||||
import { getMessages } from 'next-intl/server';
|
||||
import { notFound } from 'next/navigation';
|
||||
import { locales } from '../../i18n/request';
|
||||
|
||||
export default async function LocaleLayout({
|
||||
children,
|
||||
params
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
params: Promise<{ locale: string }>;
|
||||
}) {
|
||||
const { locale } = await params;
|
||||
|
||||
// Ensure that the incoming `locale` is valid
|
||||
if (!locales.includes(locale as (typeof locales)[number])) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
// Providing all messages to the client
|
||||
// side is the easiest way to get started
|
||||
const messages = await getMessages();
|
||||
|
||||
return (
|
||||
<NextIntlClientProvider messages={messages}>
|
||||
{children}
|
||||
</NextIntlClientProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { useIsMobile } from '../hooks/useIsMobile';
|
||||
import Image from 'next/image';
|
||||
import { FloatingHearts } from '../components/FloatingHearts';
|
||||
import { ThemeToggle } from '../components/ThemeToggle';
|
||||
import { SpeechBubble } from '../components/SpeechBubble';
|
||||
import { SkinSelector } from '../components/SkinSelector';
|
||||
import { shakeConfig } from '../config/shake';
|
||||
import { ArrowTopRightOnSquareIcon } from '@heroicons/react/24/outline';
|
||||
import { appConfig } from '../config/app';
|
||||
import { useSkin } from '../hooks/useSkin';
|
||||
import { LanguageToggle } from '../components/LanguageToggle';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useLocalizedSkinName } from '../hooks/useLocalizedSkinName';
|
||||
|
||||
export default function Home() {
|
||||
const [isShaken, setIsShaken] = useState(false);
|
||||
const [shakeIntensity, setShakeIntensity] = useState(0);
|
||||
const [lastUpdate, setLastUpdate] = useState(0);
|
||||
const [shakeCount, setShakeCount] = useState(0);
|
||||
const [motionPermission, setMotionPermission] = useState<PermissionState>('prompt');
|
||||
const isMobile = useIsMobile();
|
||||
const [, setIsAnimating] = useState(false);
|
||||
const [, setShakeQueue] = useState<number[]>([]);
|
||||
const isAnimatingRef = useRef<boolean>(false);
|
||||
const animationTimeoutRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
||||
const animationStartTimeRef = useRef<number>(0);
|
||||
const currentSkin = useSkin();
|
||||
const getLocalizedSkinName = useLocalizedSkinName();
|
||||
const t = useTranslations('ui');
|
||||
|
||||
const requestMotionPermission = async () => {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
if (!('DeviceMotionEvent' in window)) {
|
||||
setMotionPermission('denied');
|
||||
return;
|
||||
}
|
||||
|
||||
if ('requestPermission' in DeviceMotionEvent) {
|
||||
try {
|
||||
// @ts-expect-error - TypeScript doesn't know about requestPermission
|
||||
const permission = await DeviceMotionEvent.requestPermission();
|
||||
setMotionPermission(permission);
|
||||
} catch (err) {
|
||||
console.error('Error requesting motion permission:', err);
|
||||
setMotionPermission('denied');
|
||||
}
|
||||
} else {
|
||||
setMotionPermission('granted');
|
||||
}
|
||||
};
|
||||
|
||||
const triggerShake = useCallback((intensity: number) => {
|
||||
if (!isAnimatingRef.current) {
|
||||
if (animationTimeoutRef.current) {
|
||||
clearTimeout(animationTimeoutRef.current);
|
||||
}
|
||||
|
||||
isAnimatingRef.current = true;
|
||||
animationStartTimeRef.current = Date.now();
|
||||
setIsAnimating(true);
|
||||
setIsShaken(true);
|
||||
setShakeIntensity(intensity);
|
||||
setShakeCount(count => count + 1);
|
||||
|
||||
animationTimeoutRef.current = setTimeout(() => {
|
||||
setIsShaken(false);
|
||||
setShakeIntensity(0);
|
||||
setIsAnimating(false);
|
||||
isAnimatingRef.current = false;
|
||||
|
||||
setShakeQueue(prev => {
|
||||
if (prev.length > 0) {
|
||||
const [nextIntensity, ...rest] = prev;
|
||||
setTimeout(() => {
|
||||
triggerShake(nextIntensity);
|
||||
}, 16);
|
||||
return rest;
|
||||
}
|
||||
return prev;
|
||||
});
|
||||
}, shakeConfig.animations.shakeReset);
|
||||
} else {
|
||||
const timeSinceStart = Date.now() - animationStartTimeRef.current;
|
||||
if (timeSinceStart > 100) {
|
||||
setShakeQueue(prev => {
|
||||
if (prev.length >= 1) return prev;
|
||||
return [...prev, intensity];
|
||||
});
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyPress = (event: KeyboardEvent) => {
|
||||
if (event.code === 'Space') {
|
||||
triggerShake(shakeConfig.defaultTriggerIntensity);
|
||||
}
|
||||
};
|
||||
|
||||
const handleMotion = (event: DeviceMotionEvent) => {
|
||||
const acceleration = event.accelerationIncludingGravity;
|
||||
if (!acceleration) return;
|
||||
|
||||
const currentTime = new Date().getTime();
|
||||
const timeDiff = currentTime - lastUpdate;
|
||||
|
||||
if (timeDiff > shakeConfig.debounceTime) {
|
||||
setLastUpdate(currentTime);
|
||||
|
||||
const speed = Math.abs(acceleration.x || 0) +
|
||||
Math.abs(acceleration.y || 0) +
|
||||
Math.abs(acceleration.z || 0);
|
||||
|
||||
if (speed > shakeConfig.threshold) {
|
||||
triggerShake(speed);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
if (motionPermission === 'granted' && 'DeviceMotionEvent' in window) {
|
||||
window.addEventListener('devicemotion', handleMotion);
|
||||
}
|
||||
window.addEventListener('keydown', handleKeyPress);
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (typeof window !== 'undefined') {
|
||||
if (motionPermission === 'granted') {
|
||||
window.removeEventListener('devicemotion', handleMotion);
|
||||
}
|
||||
window.removeEventListener('keydown', handleKeyPress);
|
||||
}
|
||||
};
|
||||
}, [lastUpdate, motionPermission, triggerShake]);
|
||||
|
||||
useEffect(() => {
|
||||
requestMotionPermission();
|
||||
}, []);
|
||||
|
||||
const handleClick = () => {
|
||||
if ('vibrate' in navigator) {
|
||||
navigator.vibrate(50); // Short 50ms vibration
|
||||
}
|
||||
triggerShake(shakeConfig.defaultTriggerIntensity);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (animationTimeoutRef.current) {
|
||||
clearTimeout(animationTimeoutRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="flex h-[100dvh] flex-col items-center justify-between p-4 bg-green-50 dark:bg-slate-900 relative">
|
||||
<div className="w-full flex justify-between items-center">
|
||||
<div className="flex items-center gap-2">
|
||||
<LanguageToggle />
|
||||
<SkinSelector />
|
||||
</div>
|
||||
<ThemeToggle />
|
||||
</div>
|
||||
<div className="flex-1 flex flex-col items-center justify-center w-full">
|
||||
<div className="fixed inset-0 overflow-hidden pointer-events-none">
|
||||
<FloatingHearts intensity={shakeIntensity} />
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={handleClick}
|
||||
className="relative z-10"
|
||||
aria-label={t('shakeCharacter', { item: getLocalizedSkinName(currentSkin) })}
|
||||
>
|
||||
<FloatingHearts intensity={shakeIntensity} />
|
||||
<SpeechBubble
|
||||
isShaken={isShaken}
|
||||
triggerCount={shakeCount}
|
||||
/>
|
||||
<Image
|
||||
src={isShaken
|
||||
? appConfig.skins[currentSkin].shaken
|
||||
: appConfig.skins[currentSkin].normal
|
||||
}
|
||||
alt={getLocalizedSkinName(currentSkin)}
|
||||
width={200}
|
||||
height={200}
|
||||
priority
|
||||
className={isShaken ? 'animate-shake' : ''}
|
||||
/>
|
||||
</button>
|
||||
|
||||
<div className="mt-8 flex flex-col items-center gap-2">
|
||||
<p className="text-gray-600 dark:text-gray-400 text-center max-w-[240px]">
|
||||
{motionPermission === 'prompt' ? (
|
||||
<button
|
||||
onClick={requestMotionPermission}
|
||||
className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors"
|
||||
>
|
||||
{t('enableDeviceShake')}
|
||||
</button>
|
||||
) : motionPermission === 'granted' ? (
|
||||
t(
|
||||
isMobile ? 'shakeInstructionsMobile' : 'shakeInstructionsDesktop',
|
||||
{ item: getLocalizedSkinName(currentSkin) }
|
||||
)
|
||||
) : (
|
||||
t(
|
||||
isMobile ? 'noShakeInstructionsMobile' : 'noShakeInstructionsDesktop',
|
||||
{ item: getLocalizedSkinName(currentSkin) }
|
||||
)
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer className="w-full text-center text-xs text-gray-400 dark:text-gray-600 mt-auto pt-4">
|
||||
© {new Date().getFullYear()}{' '}
|
||||
<a
|
||||
href="https://github.com/HugeFrog24/shakethefrog"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="hover:text-gray-600 dark:hover:text-gray-400 transition-colors inline-flex items-center gap-1"
|
||||
>
|
||||
{appConfig.name}
|
||||
<ArrowTopRightOnSquareIcon className="w-3 h-3" />
|
||||
</a>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user