Compare commits
No commits in common. "d3cded434439933908db8c1c4768dd2b67bfc57f" and "cf9dd8a3d1391588c5a24577e14fa250ff675f89" have entirely different histories.
d3cded4344
...
cf9dd8a3d1
|
|
@ -1,8 +1,5 @@
|
||||||
import { useWeatherStore } from "@/store/weatherStore";
|
import { useWeatherStore } from "@/store/weatherStore";
|
||||||
import { Cloud } from "lucide-react";
|
import { Cloud } from "lucide-react";
|
||||||
import {WeatherDisplay } from '@/components/WeatherDisplay'
|
|
||||||
import { WeatherSearchForm } from "./WeatherSearchForm";
|
|
||||||
import { WeatherDetailsGrid } from "./WeatherDetailsGird";
|
|
||||||
|
|
||||||
export function WeatherCard(){
|
export function WeatherCard(){
|
||||||
const{ currentWeather} = useWeatherStore();
|
const{ currentWeather} = useWeatherStore();
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { useWeatherStore } from '@/store/weatherStore';
|
||||||
|
|
||||||
|
|
||||||
export function WeatherSearchForm() {
|
export function WeatherSearchForm() {
|
||||||
const {isLoading, currentWeather, searchWeather, refreshWeather} = useWeatherStore();
|
const [isLoading, currentWeather, searchWeather, refreshWeather] = useWeatherStore();
|
||||||
|
|
||||||
const [city, setCity] = useState('');
|
const [city, setCity] = useState('');
|
||||||
const [inputError, setInputError] = useState('');
|
const [inputError, setInputError] = useState('');
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { create } from 'zustand'
|
import { create } from 'zustand'
|
||||||
import {persist,createJSONStorage} from 'zustand/middleware'
|
import {persist,createJSONStorage} from 'zustand/middleware'
|
||||||
import { WeatherApi } from '@/services/weatherApi';
|
|
||||||
const CACHE_EXPIRY = 10 * 60 * 1000;
|
const CACHE_EXPIRY = 10 * 60 * 1000;
|
||||||
|
|
||||||
export interface Location {
|
export interface Location {
|
||||||
|
|
@ -99,7 +98,7 @@ export const useWeatherStore = create<WeatherStore>()(
|
||||||
set({currentWeather:cachedWeather,isLoading:false});
|
set({currentWeather:cachedWeather,isLoading:false});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const WeatherData = await WeatherApi.getCurrentWeather(city);
|
const WeatherData = await WeatherAPI.getcurrentWeather(city);
|
||||||
set({currentWeather:WeatherData,isLoading:false});
|
set({currentWeather:WeatherData,isLoading:false});
|
||||||
get().cacheWeather(city,WeatherData);
|
get().cacheWeather(city,WeatherData);
|
||||||
}catch(error){
|
}catch(error){
|
||||||
|
|
@ -112,7 +111,7 @@ export const useWeatherStore = create<WeatherStore>()(
|
||||||
try{
|
try{
|
||||||
set({isLoading:true,error:null});
|
set({isLoading:true,error:null});
|
||||||
const city = currentWeather.location.name;
|
const city = currentWeather.location.name;
|
||||||
const WeatherData = await WeatherApi.getCurrentWeather(city);
|
const WeatherData = await WeatherAPI.getcurrentWeather(city);
|
||||||
set({currentWeather:WeatherData,isLoading:false});
|
set({currentWeather:WeatherData,isLoading:false});
|
||||||
get().cacheWeather(city,WeatherData);
|
get().cacheWeather(city,WeatherData);
|
||||||
}catch(error){
|
}catch(error){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue