fix: improve rating UI label and notification context
This commit is contained in:
@@ -34,7 +34,7 @@ export async function sendGotifyNotification(attempts: number, status: 'won' | '
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export async function submitRating(songId: number, rating: number, genre?: string | null) {
|
||||
export async function submitRating(songId: number, rating: number, genre?: string | null, isSpecial?: boolean, puzzleNumber?: number) {
|
||||
try {
|
||||
const song = await prisma.song.findUnique({ where: { id: songId } });
|
||||
if (!song) throw new Error('Song not found');
|
||||
@@ -51,9 +51,17 @@ export async function submitRating(songId: number, rating: number, genre?: strin
|
||||
});
|
||||
|
||||
// Send Gotify notification for the rating
|
||||
const genreText = genre ? `[${genre}] ` : '';
|
||||
let context = 'Global Daily Puzzle';
|
||||
if (genre) {
|
||||
context = isSpecial ? `Special Puzzle "${genre}"` : `Genre Puzzle "${genre}"`;
|
||||
}
|
||||
if (puzzleNumber) {
|
||||
context += ` #${puzzleNumber}`;
|
||||
}
|
||||
|
||||
const title = `Hördle Rating: ${rating} Stars`;
|
||||
const message = `Song "${song.title}" by ${song.artist} ${genreText}received a ${rating}-star rating. (Avg: ${newAverageRating.toFixed(2)}, Count: ${newRatingCount})`;
|
||||
// Do not show song title/artist to avoid spoilers
|
||||
const message = `${context} received a ${rating}-star rating.\nNew Average: ${newAverageRating.toFixed(2)} (${newRatingCount} ratings)`;
|
||||
|
||||
await fetch(`${GOTIFY_URL}/message?token=${GOTIFY_APP_TOKEN}`, {
|
||||
method: 'POST',
|
||||
|
||||
@@ -65,6 +65,17 @@ export default function Game({ dailyPuzzle, genre = null, isSpecial = false, max
|
||||
setLastAction(null);
|
||||
}, [dailyPuzzle?.id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (dailyPuzzle) {
|
||||
const ratedPuzzles = JSON.parse(localStorage.getItem('hoerdle_rated_puzzles') || '[]');
|
||||
if (ratedPuzzles.includes(dailyPuzzle.id)) {
|
||||
setHasRated(true);
|
||||
} else {
|
||||
setHasRated(false);
|
||||
}
|
||||
}
|
||||
}, [dailyPuzzle]);
|
||||
|
||||
if (!dailyPuzzle) return (
|
||||
<div className="game-container" style={{ textAlign: 'center', padding: '2rem' }}>
|
||||
<h2>No Puzzle Available</h2>
|
||||
@@ -181,22 +192,13 @@ export default function Game({ dailyPuzzle, genre = null, isSpecial = false, max
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (dailyPuzzle) {
|
||||
const ratedPuzzles = JSON.parse(localStorage.getItem('hoerdle_rated_puzzles') || '[]');
|
||||
if (ratedPuzzles.includes(dailyPuzzle.id)) {
|
||||
setHasRated(true);
|
||||
} else {
|
||||
setHasRated(false);
|
||||
}
|
||||
}
|
||||
}, [dailyPuzzle]);
|
||||
|
||||
|
||||
const handleRatingSubmit = async (rating: number) => {
|
||||
if (!dailyPuzzle) return;
|
||||
|
||||
try {
|
||||
await submitRating(dailyPuzzle.songId, rating, genre);
|
||||
await submitRating(dailyPuzzle.songId, rating, genre, isSpecial, dailyPuzzle.puzzleNumber);
|
||||
setHasRated(true);
|
||||
|
||||
// Persist to localStorage
|
||||
@@ -356,7 +358,7 @@ function StarRating({ onRate, hasRated }: { onRate: (rating: number) => void, ha
|
||||
|
||||
return (
|
||||
<div className="star-rating" style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '0.5rem' }}>
|
||||
<span style={{ fontSize: '0.875rem', color: '#666', fontWeight: '500' }}>Rate this song:</span>
|
||||
<span style={{ fontSize: '0.875rem', color: '#666', fontWeight: '500' }}>Rate this puzzle:</span>
|
||||
<div style={{ display: 'flex', gap: '0.25rem', justifyContent: 'center' }}>
|
||||
{[...Array(5)].map((_, index) => {
|
||||
const ratingValue = index + 1;
|
||||
|
||||
Reference in New Issue
Block a user