Feat: Auto-play on skip & Gotify notifications
This commit is contained in:
@@ -5,6 +5,7 @@ import AudioPlayer from './AudioPlayer';
|
||||
import GuessInput from './GuessInput';
|
||||
import Statistics from './Statistics';
|
||||
import { useGameState } from '../lib/gameState';
|
||||
import { sendGotifyNotification } from '../app/actions';
|
||||
|
||||
interface GameProps {
|
||||
dailyPuzzle: {
|
||||
@@ -24,6 +25,7 @@ export default function Game({ dailyPuzzle }: GameProps) {
|
||||
const [hasWon, setHasWon] = useState(false);
|
||||
const [hasLost, setHasLost] = useState(false);
|
||||
const [shareText, setShareText] = useState('Share Result');
|
||||
const [lastAction, setLastAction] = useState<'GUESS' | 'SKIP' | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (gameState && dailyPuzzle) {
|
||||
@@ -32,6 +34,10 @@ export default function Game({ dailyPuzzle }: GameProps) {
|
||||
}
|
||||
}, [gameState, dailyPuzzle]);
|
||||
|
||||
useEffect(() => {
|
||||
setLastAction(null);
|
||||
}, [dailyPuzzle?.id]);
|
||||
|
||||
if (!dailyPuzzle) return (
|
||||
<div className="game-container" style={{ textAlign: 'center', padding: '2rem' }}>
|
||||
<h2>No Puzzle Available</h2>
|
||||
@@ -43,17 +49,32 @@ export default function Game({ dailyPuzzle }: GameProps) {
|
||||
if (!gameState) return <div>Loading state...</div>;
|
||||
|
||||
const handleGuess = (song: any) => {
|
||||
setLastAction('GUESS');
|
||||
if (song.id === dailyPuzzle.songId) {
|
||||
addGuess(song.title, true);
|
||||
setHasWon(true);
|
||||
sendGotifyNotification(gameState.guesses.length + 1, 'won', dailyPuzzle.id);
|
||||
} else {
|
||||
addGuess(song.title, false);
|
||||
if (gameState.guesses.length + 1 >= 7) {
|
||||
setHasLost(true);
|
||||
sendGotifyNotification(7, 'lost', dailyPuzzle.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleSkip = () => {
|
||||
setLastAction('SKIP');
|
||||
addGuess("SKIPPED", false);
|
||||
};
|
||||
|
||||
const handleGiveUp = () => {
|
||||
setLastAction('SKIP');
|
||||
addGuess("SKIPPED", false);
|
||||
setHasLost(true);
|
||||
sendGotifyNotification(7, 'lost', dailyPuzzle.id);
|
||||
};
|
||||
|
||||
const unlockedSeconds = UNLOCK_STEPS[Math.min(gameState.guesses.length, 6)];
|
||||
|
||||
const handleShare = () => {
|
||||
@@ -116,6 +137,7 @@ export default function Game({ dailyPuzzle }: GameProps) {
|
||||
<AudioPlayer
|
||||
src={dailyPuzzle.audioUrl}
|
||||
unlockedSeconds={unlockedSeconds}
|
||||
autoPlay={lastAction === 'SKIP'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -138,17 +160,14 @@ export default function Game({ dailyPuzzle }: GameProps) {
|
||||
<GuessInput onGuess={handleGuess} disabled={false} />
|
||||
{gameState.guesses.length < 6 ? (
|
||||
<button
|
||||
onClick={() => addGuess("SKIPPED", false)}
|
||||
onClick={handleSkip}
|
||||
className="skip-button"
|
||||
>
|
||||
Skip (+{UNLOCK_STEPS[Math.min(gameState.guesses.length + 1, 6)] - unlockedSeconds}s)
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => {
|
||||
addGuess("SKIPPED", false);
|
||||
setHasLost(true);
|
||||
}}
|
||||
onClick={handleGiveUp}
|
||||
className="skip-button"
|
||||
style={{
|
||||
background: 'linear-gradient(135deg, #f093fb 0%, #f5576c 100%)',
|
||||
|
||||
Reference in New Issue
Block a user