This commit is contained in:
qiuchenfan 2025-11-17 19:23:22 +08:00
parent 4bf2c78132
commit 1ee461ccd1
3 changed files with 7 additions and 3 deletions

View File

@ -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();

View File

@ -7,7 +7,7 @@ import { useWeatherStore } from '@/store/weatherStore';
export function WeatherSearchForm() {
const [isLoading, currentWeather, searchWeather, refreshWeather] = useWeatherStore();
const {isLoading, currentWeather, searchWeather, refreshWeather} = useWeatherStore();
const [city, setCity] = useState('');
const [inputError, setInputError] = useState('');

View File

@ -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<WeatherStore>()(
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<WeatherStore>()(
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){