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',
|
||||
|
||||
Reference in New Issue
Block a user