Skip to content

Commit 6735a22

Browse files
committed
error in weather.tsx file
1 parent 70123ee commit 6735a22

File tree

1 file changed

+35
-100
lines changed

1 file changed

+35
-100
lines changed

src/pages/Weather.jsx

Lines changed: 35 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -411,39 +411,41 @@ export default function Weather() {
411411
Switch to °{unit === "C" ? "F" : "C"}
412412
</button>
413413
</div>
414-
{loading && <Loading />}
415-
{error && (
416-
<ErrorMessage
417-
message={error.message}
418-
onRetry={() => fetchWeather(city)}
419-
/>
420-
)}
421-
422-
{data && !loading && (
423-
<div className="dashboard-grid">
424-
{/* Current Weather */}
425-
<Card title="Current Weather" size="large">
426-
<h2>{data.nearest_area?.[0]?.areaName?.[0]?.value || city}</h2>
427-
<p style={{ display: "flex", alignItems: "center", gap: "12px" }}>
428-
{current && getIconUrl(current.weatherIconUrl) && (
429-
<img
430-
src={getIconUrl(current.weatherIconUrl)}
431-
alt={current.weatherDesc?.[0]?.value || "weather icon"}
432-
style={{ width: 48, height: 48, objectFit: "contain" }}
433-
/>
434-
)}
435-
<span>
436-
<strong>Temperature:</strong>{" "}
437-
{displayTemp(Number(current.temp_C))}°{unit}
438-
</span>
439-
</p>
440-
<p>
441-
<strong>Humidity:</strong> {current.humidity}%
442-
</p>
443-
<p>
444-
<strong>Desc:</strong> {current.weatherDesc?.[0]?.value}
445-
</p>
446-
</Card>
414+
</div>
415+
416+
{loading && <Loading />}
417+
{error && (
418+
<ErrorMessage
419+
message={error.message}
420+
onRetry={() => fetchWeather(city)}
421+
/>
422+
)}
423+
424+
{data && !loading && (
425+
<div className="dashboard-grid">
426+
{/* Current Weather */}
427+
<Card title="Current Weather" size="large">
428+
<h2>{data.nearest_area?.[0]?.areaName?.[0]?.value || city}</h2>
429+
<p style={{ display: "flex", alignItems: "center", gap: "12px" }}>
430+
{current && getIconUrl(current.weatherIconUrl) && (
431+
<img
432+
src={getIconUrl(current.weatherIconUrl)}
433+
alt={current.weatherDesc?.[0]?.value || "weather icon"}
434+
style={{ width: 48, height: 48, objectFit: "contain" }}
435+
/>
436+
)}
437+
<span>
438+
<strong>Temperature:</strong>{" "}
439+
{displayTemp(Number(current.temp_C))}°{unit}
440+
</span>
441+
</p>
442+
<p>
443+
<strong>Humidity:</strong> {current.humidity}%
444+
</p>
445+
<p>
446+
<strong>Desc:</strong> {current.weatherDesc?.[0]?.value}
447+
</p>
448+
</Card>
447449

448450
{/* 3-Day Forecast */}
449451
{forecast.map((day, i) => {
@@ -570,73 +572,6 @@ export default function Weather() {
570572
);
571573
})}
572574
</div>
573-
574-
{loading && <Loading />}
575-
{error && (
576-
<ErrorMessage
577-
message={error.message}
578-
onRetry={() => fetchWeather(city)}
579-
/>
580-
)}
581-
582-
{data && !loading && (
583-
<div
584-
className="dashboard-grid"
585-
style={{ position: "relative", zIndex: 10 }}
586-
>
587-
{/* Current Weather */}
588-
<Card title="Current Weather" size="large">
589-
<h2>{data.nearest_area?.[0]?.areaName?.[0]?.value || city}</h2>
590-
<p>
591-
<strong>Temperature:</strong>{" "}
592-
{displayTemp(Number(current.temp_C))}°{unit}
593-
</p>
594-
<p>
595-
<strong>Humidity:</strong> {current.humidity}%
596-
</p>
597-
<p>
598-
<strong>Desc:</strong> {current.weatherDesc?.[0]?.value}
599-
</p>
600-
</Card>
601-
602-
{/* 3-Day Forecast */}
603-
{forecast.map((day, i) => {
604-
const condition =
605-
day.hourly?.[0]?.weatherDesc?.[0]?.value || "Clear";
606-
const badge = getBadgeStyle(condition);
607-
608-
return (
609-
<Card key={i} title={i === 0 ? "Today" : `Day ${i + 1}`}>
610-
{/* Badge Section */}
611-
<div
612-
style={{
613-
backgroundColor: badge.color,
614-
borderRadius: "8px",
615-
padding: "4px 8px",
616-
display: "inline-block",
617-
fontSize: "12px",
618-
fontWeight: "bold",
619-
marginBottom: "8px",
620-
color: "#333",
621-
}}
622-
>
623-
{badge.label}
624-
</div>
625-
626-
<p>
627-
<strong>Avg Temp:</strong> {displayTemp(Number(day.avgtempC))}
628-
°{unit}
629-
</p>
630-
<p>
631-
<strong>Sunrise:</strong> {day.astronomy?.[0]?.sunrise}
632-
</p>
633-
<p>
634-
<strong>Sunset:</strong> {day.astronomy?.[0]?.sunset}
635-
</p>
636-
</Card>
637-
);
638-
})}
639-
</div>
640575
)}
641576
</div>
642577
</div>

0 commit comments

Comments
 (0)