fix(logic): use sequential puzzle number instead of database ID

This commit is contained in:
Hördle Bot
2025-11-23 00:12:04 +01:00
parent 77a769fb91
commit 4b9e7ac9ec
2 changed files with 30 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ import { sendGotifyNotification } from '../app/actions';
interface GameProps { interface GameProps {
dailyPuzzle: { dailyPuzzle: {
id: number; id: number;
puzzleNumber: number;
audioUrl: string; audioUrl: string;
songId: number; songId: number;
title: string; title: string;
@@ -141,7 +142,7 @@ export default function Game({ dailyPuzzle, genre = null, isSpecial = false, max
} }
} }
const text = `Hördle #${dailyPuzzle.id}\n${genreText}\n${speaker}${emojiGrid}\n\n#Hördle #Music\n\n${shareUrl}`; const text = `Hördle #${dailyPuzzle.puzzleNumber}\n${genreText}\n${speaker}${emojiGrid}\n\n#Hördle #Music\n\n${shareUrl}`;
// Try native Web Share API only on mobile devices // Try native Web Share API only on mobile devices
const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
@@ -149,7 +150,7 @@ export default function Game({ dailyPuzzle, genre = null, isSpecial = false, max
if (isMobile && navigator.share) { if (isMobile && navigator.share) {
try { try {
await navigator.share({ await navigator.share({
title: `Hördle #${dailyPuzzle.id}`, title: `Hördle #${dailyPuzzle.puzzleNumber}`,
text: text, text: text,
}); });
setShareText('✓ Shared!'); setShareText('✓ Shared!');
@@ -178,7 +179,7 @@ export default function Game({ dailyPuzzle, genre = null, isSpecial = false, max
return ( return (
<div className="container"> <div className="container">
<header className="header"> <header className="header">
<h1 className="title">Hördle #{dailyPuzzle.id}{genre ? ` / ${genre}` : ''}</h1> <h1 className="title">Hördle #{dailyPuzzle.puzzleNumber}{genre ? ` / ${genre}` : ''}</h1>
<div style={{ fontSize: '0.9rem', color: '#666', marginTop: '-0.5rem', marginBottom: '1rem' }}> <div style={{ fontSize: '0.9rem', color: '#666', marginTop: '-0.5rem', marginBottom: '1rem' }}>
Next puzzle in: {timeUntilNext} Next puzzle in: {timeUntilNext}
</div> </div>

View File

@@ -96,8 +96,23 @@ export async function getOrCreateDailyPuzzle(genreName: string | null = null) {
if (!dailyPuzzle) return null; if (!dailyPuzzle) return null;
// Calculate puzzle number (sequential day count)
const whereClause = genreId
? { genreId: genreId }
: { genreId: null, specialId: null };
const puzzleCount = await prisma.dailyPuzzle.count({
where: {
...whereClause,
date: {
lte: dailyPuzzle.date
}
}
});
return { return {
id: dailyPuzzle.id, id: dailyPuzzle.id,
puzzleNumber: puzzleCount,
audioUrl: `/api/audio/${dailyPuzzle.song.filename}`, audioUrl: `/api/audio/${dailyPuzzle.song.filename}`,
songId: dailyPuzzle.songId, songId: dailyPuzzle.songId,
title: dailyPuzzle.song.title, title: dailyPuzzle.song.title,
@@ -183,8 +198,19 @@ export async function getOrCreateSpecialPuzzle(specialName: string) {
if (!dailyPuzzle) return null; if (!dailyPuzzle) return null;
// Calculate puzzle number
const puzzleCount = await prisma.dailyPuzzle.count({
where: {
specialId: special.id,
date: {
lte: dailyPuzzle.date
}
}
});
return { return {
id: dailyPuzzle.id, id: dailyPuzzle.id,
puzzleNumber: puzzleCount,
audioUrl: `/api/audio/${dailyPuzzle.song.filename}`, audioUrl: `/api/audio/${dailyPuzzle.song.filename}`,
songId: dailyPuzzle.songId, songId: dailyPuzzle.songId,
title: dailyPuzzle.song.title, title: dailyPuzzle.song.title,