1- import React , { useEffect , useRef , useState } from 'react'
2- import Mood from './components/Mood'
1+ import React , { useEffect , useRef , useState } from 'react' ;
2+ import Mood from './components/Mood' ;
33const App = ( ) => {
4- const [ mood , setMood ] = useState ( null ) ;
4+ const [ mood , setMood ] = useState ( null ) ;
55 const audioRef = useRef ( null ) ;
6- useEffect ( ( ) => {
7- if ( mood && audioRef . current ) {
6+
7+ const getBackgroundClass = ( ) => {
8+ if ( ! mood ) return 'bg-gradient-to-r from-purple-500 to-pink-500' ;
9+
10+ switch ( mood . color ) {
11+ case 'blue' :
12+ return 'bg-gradient-to-r from-blue-400 to-blue-600' ;
13+ case 'grey' :
14+ return 'bg-gradient-to-r from-gray-400 to-gray-600' ;
15+ case 'red' :
16+ return 'bg-gradient-to-r from-red-400 to-red-600' ;
17+ default :
18+ return 'bg-gradient-to-r from-purple-500 to-pink-500' ;
19+ }
20+ } ;
21+
22+ useEffect ( ( ) => {
23+ if ( mood && audioRef . current ) {
824 audioRef . current . pause ( ) ;
925 audioRef . current . load ( ) ;
1026 audioRef . current . play ( ) ;
1127 }
12- } , [ mood ] )
28+ } , [ mood ] ) ;
1329 return (
14- < div className = 'h-screen w-full flex flex-col justify-center items-center bg-gradient-to-r from-purple-500 to-pink-500' >
15- < h1 className = 'text-3xl' > mood based songs</ h1 >
16- < Mood onMoodChange = { setMood } />
17- { mood && (
30+ < div
31+ className = { `h-screen w-full flex flex-col justify-center items-center transition-all duration-500 ${ getBackgroundClass ( ) } ` }
32+ >
33+ < h1 className = "text-3xl" > mood based songs</ h1 >
34+ < Mood onMoodChange = { setMood } />
35+ { mood && (
1836 < div >
19- < h2 className = ' text-2xl m-3 mt-4' > { mood . message } </ h2 >
20- < audio src = "" ref = { audioRef } controls className = ' mt-7' >
21- < source src = { mood . music } type = ' audio/mp3' />
37+ < h2 className = " text-2xl m-3 mt-4" > { mood . message } </ h2 >
38+ < audio src = "" ref = { audioRef } controls className = " mt-7" >
39+ < source src = { mood . music } type = " audio/mp3" />
2240 </ audio >
23- </ div >
24- ) }
41+ </ div >
42+ ) }
2543 </ div >
26- )
27- }
44+ ) ;
45+ } ;
2846
29- export default App
47+ export default App ;
0 commit comments