Compare commits
2 Commits
cf9dd8a3d1
...
d3cded4344
| Author | SHA1 | Date |
|---|---|---|
|
|
d3cded4344 | |
|
|
1ee461ccd1 |
|
|
@ -1,5 +1,8 @@
|
||||||
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,5 +1,6 @@
|
||||||
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 {
|
||||||
|
|
@ -98,7 +99,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){
|
||||||
|
|
@ -111,7 +112,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