Compare commits
2 Commits
cf9dd8a3d1
...
d3cded4344
| Author | SHA1 | Date |
|---|---|---|
|
|
d3cded4344 | |
|
|
1ee461ccd1 |
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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('');
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
Loading…
Reference in New Issue