diff --git a/public/badgeAwarded.mp3 b/public/badgeAwarded.mp3 new file mode 100644 index 00000000..68dad2d8 Binary files /dev/null and b/public/badgeAwarded.mp3 differ diff --git a/src/components/BadgeAwardModal.tsx b/src/components/BadgeAwardModal.tsx index 67538acc..c20e128b 100644 --- a/src/components/BadgeAwardModal.tsx +++ b/src/components/BadgeAwardModal.tsx @@ -1,10 +1,10 @@ +import { useEffect, useRef } from 'react'; import { Dialog, DialogContent, DialogTitle, DialogDescription } from "@/components/ui/dialog"; import { Award } from "lucide-react"; import type { NostrEvent } from '@nostrify/nostrify'; import { useNostr } from '@nostrify/react'; import { useQuery } from '@tanstack/react-query'; import { Skeleton } from "@/components/ui/skeleton"; -import { cn } from '@/lib/utils'; const BADGE_ISSUER_PUBKEY = "804a5a94d972d2218d2cc8712881e6f00df09fe7a1a269ccbf916e5c8c17efcc"; @@ -16,6 +16,7 @@ interface BadgeAwardModalProps { export function BadgeAwardModal({ award, badgeDefinition: providedBadgeDefinition, onClose }: BadgeAwardModalProps) { const { nostr } = useNostr(); + const audioRef = useRef(null); // If we have a badge definition directly, use it // Otherwise, extract from award event @@ -53,6 +54,24 @@ export function BadgeAwardModal({ award, badgeDefinition: providedBadgeDefinitio const badgeDefinition = providedBadgeDefinition || fetchedBadgeDefinition; const isModalOpen = !!award || !!providedBadgeDefinition; + // Play sound when badge is awarded (only when award is present, not just viewing badge definition) + useEffect(() => { + if (award && badgeDefinition && isModalOpen && !isLoading) { + // Create audio element if it doesn't exist + if (!audioRef.current) { + audioRef.current = new Audio('/badgeAwarded.mp3'); + audioRef.current.volume = 0.5; // Set volume to 50% + } + + // Reset to beginning and play the sound + audioRef.current.currentTime = 0; + audioRef.current.play().catch((error) => { + // Silently handle autoplay restrictions + console.debug('Audio playback failed:', error); + }); + } + }, [award, badgeDefinition, isModalOpen, isLoading]); + // Return null after all hooks if we don't have a badge definition if (!badgeDefinition) return null; @@ -100,7 +119,6 @@ export function BadgeAwardModal({ award, badgeDefinition: providedBadgeDefinitio {/* Title */}
- {award &&

Badge Awarded!

}

{badgeName}

{description && (

diff --git a/src/pages/BadgesSettings.tsx b/src/pages/BadgesSettings.tsx index 2c468896..f5d22dca 100644 --- a/src/pages/BadgesSettings.tsx +++ b/src/pages/BadgesSettings.tsx @@ -37,10 +37,10 @@ function BadgeCard({ const formattedDate = unlockDate ? new Date(unlockDate * 1000).toLocaleDateString('en-US', { - year: 'numeric', - month: 'short', - day: 'numeric' - }) + year: 'numeric', + month: 'short', + day: 'numeric' + }) : null; return ( diff --git a/vite.config.ts b/vite.config.ts index 6a981e21..3f6b4075 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -29,7 +29,7 @@ export default defineConfig(() => ({ plugins: [ react(), VitePWA({ - includeAssets: ['shakespeare.svg', 'shakespeare-192x192.png', 'shakespeare-512x512.png', 'sine.mp3'], + includeAssets: ['shakespeare.svg', 'shakespeare-192x192.png', 'shakespeare-512x512.png', 'sine.mp3', 'badgeAwarded.mp3'], manifest: false, // Use existing manifest.webmanifest from public folder workbox: { globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2,wasm,mp3}'],