File tree Expand file tree Collapse file tree 3 files changed +18
-12
lines changed
Expand file tree Collapse file tree 3 files changed +18
-12
lines changed Original file line number Diff line number Diff line change 1- VITE_OMDB_API_KEY = your_api_key_here
1+ VITE_OMDB_API_KEY = your_api_key_here
2+ VITE_WEATHER_API_KEY = your_api_key_here
Original file line number Diff line number Diff line change 99 "preview" : " vite preview"
1010 },
1111 "dependencies" : {
12+ "idb" : " ^8.0.3" ,
1213 "leaflet" : " ^1.9.4" ,
1314 "lucide-react" : " ^0.546.0" ,
1415 "react" : " ^18.3.1" ,
1516 "react-dom" : " ^18.3.1" ,
1617 "react-icons" : " ^5.5.0" ,
1718 "react-leaflet" : " ^4.2.1" ,
18- "react-router-dom" : " ^6.27.0"
19+ "react-router-dom" : " ^6.27.0" ,
20+ "recharts" : " ^3.3.0"
1921 },
2022 "devDependencies" : {
2123 "@vitejs/plugin-react" : " ^4.3.1" ,
Original file line number Diff line number Diff line change @@ -83,39 +83,42 @@ export default function Weather() {
8383 const data = await res . json ( ) ;
8484 if ( data && data . length > 0 && data [ 0 ] . name ) {
8585 setCity ( data [ 0 ] . name ) ;
86- setError ( null ) ;
8786 setIsLocAllowed ( true ) ;
87+ setError ( null ) ;
8888 localStorage . setItem ( "userLocation" , JSON . stringify ( data [ 0 ] . name ) ) ;
8989 } else {
9090 setCity ( "London" ) ;
9191 setError ( "Could not detect city from location." ) ;
9292 setIsLocAllowed ( false ) ;
9393 }
9494 } catch ( err ) {
95- console . log ( err ) ;
9695 setCity ( "London" ) ;
97- setError ( err . message ) ;
96+ setError ( "Failed to fetch city from coordinates." ) ;
9897 setIsLocAllowed ( false ) ;
9998 }
10099 }
101100
102101 function requestLocation ( ) {
103102 setIsRequestingLoc ( true ) ;
103+ if ( ! navigator . geolocation ) {
104+ setError ( "Geolocation is not supported by your browser." ) ;
105+ setIsLocAllowed ( false ) ;
106+ setCity ( "London" ) ;
107+ setIsRequestingLoc ( false ) ;
108+ return ;
109+ }
110+
104111 navigator . geolocation . getCurrentPosition (
105- async function onSuccess ( position ) {
112+ async ( position ) => {
106113 await getCurrentCity (
107114 position . coords . latitude ,
108115 position . coords . longitude
109116 ) ;
110117 setIsRequestingLoc ( false ) ;
111118 } ,
112-
113- function onError ( err ) {
114- console . log ( "Error" , err ) ;
119+ ( error ) => {
120+ setError ( "Location access denied or failed." ) ;
115121 setIsLocAllowed ( false ) ;
116- setError (
117- "Location is blocked. Please enable location in your browser settings to detect automatically."
118- ) ;
119122 setCity ( "London" ) ;
120123 setIsRequestingLoc ( false ) ;
121124 }
You can’t perform that action at this time.
0 commit comments