diff --git a/app/components/WeatherCard.tsx b/app/components/WeatherCard.tsx index 257cac9..3d92654 100644 --- a/app/components/WeatherCard.tsx +++ b/app/components/WeatherCard.tsx @@ -1,5 +1,8 @@ import { useWeatherStore } from "@/store/weatherStore"; import { Cloud } from "lucide-react"; +import {WeatherDisplay } from '@/components/WeatherDisplay' +import { WeatherSearchForm } from "./WeatherSearchForm"; +import { WeatherDetailsGrid } from "./WeatherDetailsGird"; export function WeatherCard(){ const{ currentWeather} = useWeatherStore(); diff --git a/app/components/WeatherDetailsGird.tsx b/app/components/WeatherDetailsGird.tsx index 30bf498..d4fe5ff 100644 --- a/app/components/WeatherDetailsGird.tsx +++ b/app/components/WeatherDetailsGird.tsx @@ -1,5 +1,6 @@ import { Cloud, Droplets, Gauge, ThermometerSun, Wind } from "lucide-react"; import { useWeatherStore } from "@/store/weatherStore"; +import { MapPin, Thermometer } from "lucide-react"; interface WeatherDetailsGridProps { icon: React.ReactNode; diff --git a/app/components/WeatherDisplay.tsx b/app/components/WeatherDisplay.tsx new file mode 100644 index 0000000..33e8b7a --- /dev/null +++ b/app/components/WeatherDisplay.tsx @@ -0,0 +1,92 @@ + +import React from 'react'; +import { + Cloud, + CloudDrizzle, + CloudFog, + CloudLightning, CloudMoon, + CloudRain, + CloudSnow, + CloudSun, + MapPin, Moon, Sun, + Thermometer, + ThermometerSun +} from 'lucide-react'; + +import { formatTemperature } from "@/lib/utils"; +import { useWeatherStore } from '@/store/weatherStore'; +interface WeatherIconProps { + description: string; + isDay: string; + className?: string; +} + +/** + * Returns the appropriate weather icon based on description and time of day + */ +function WeatherIcon({ description, isDay, className = "w-16 h-16 md:w-20 md:h-20" }: WeatherIconProps) { + const desc = description.toLowerCase(); + const isDaytime = isDay === 'yes'; + + if (desc.includes('rain') || desc.includes('雨')) { + return desc.includes('heavy') || desc.includes('暴') + ? + : ; + } + if (desc.includes('snow') || desc.includes('雪')) return ; + if (desc.includes('thunder') || desc.includes('storm') || desc.includes('雷')) return ; + if (desc.includes('fog') || desc.includes('mist') || desc.includes('haze') || desc.includes('雾') || desc.includes('霾')) return ; + if (desc.includes('partly') || desc.includes('scattered') || desc.includes('多云')) { + return isDaytime ? : ; + } + if (desc.includes('cloudy') || desc.includes('overcast') || desc.includes('阴')) return ; + if (desc.includes('clear') || desc.includes('sunny') || desc.includes('晴')) { + return isDaytime ? : ; + } + return isDaytime ? : ; +} + + +export function WeatherDisplay(){ + const {currentWeather} = useWeatherStore(); + if(!currentWeather) return null; + + return( +
+
+
+
+
+
+

{currentWeather.location.name}

+
+ + {currentWeather.location.country} +
+
+ +
+
+
+ + {formatTemperature(currentWeather.current.temperature)} + + + °C + +
+

+ {currentWeather.current.weather_descriptions[0]} +

+
+ + 体感{formatTemperature(currentWeather.current.feelslike)}°C +
+
+
+
+ ) +} \ No newline at end of file diff --git a/app/store/weatherStore.ts b/app/store/weatherStore.ts index 8754ff9..28d4ab0 100644 --- a/app/store/weatherStore.ts +++ b/app/store/weatherStore.ts @@ -1,5 +1,6 @@ import { create } from 'zustand' import {persist,createJSONStorage} from 'zustand/middleware' +import { WeatherApi } from '@/services/weatherApi'; const CACHE_EXPIRY = 10 * 60 * 1000; export interface Location { @@ -98,7 +99,7 @@ export const useWeatherStore = create()( set({currentWeather:cachedWeather,isLoading:false}); return; } - const WeatherData = await WeatherAPI.getcurrentWeather(city); + const WeatherData = await WeatherApi.getCurrentWeather(city); set({currentWeather:WeatherData,isLoading:false}); get().cacheWeather(city,WeatherData); }catch(error){ @@ -111,7 +112,7 @@ export const useWeatherStore = create()( try{ set({isLoading:true,error:null}); const city = currentWeather.location.name; - const WeatherData = await WeatherAPI.getcurrentWeather(city); + const WeatherData = await WeatherApi.getCurrentWeather(city); set({currentWeather:WeatherData,isLoading:false}); get().cacheWeather(city,WeatherData); }catch(error){