Style updates
This commit is contained in:
@@ -178,6 +178,25 @@ export function useWeatherAPI({
|
||||
});
|
||||
}
|
||||
|
||||
export function useSunStateAPI({ lat, lon }: { lat: number; lon: number }) {
|
||||
const date = new Date();
|
||||
const today = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
||||
date.setDate(date.getDate() + 1);
|
||||
const tomorrow = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
||||
const url = `https://api.sunrisesunset.io/json?lat=${lat}&lng=${lon}&date_start=${today}&date_end=${tomorrow}`;
|
||||
const callEndpoint = async () => {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`${response.status} ${response.statusText}`);
|
||||
}
|
||||
return await response.json();
|
||||
};
|
||||
return useQuery({
|
||||
queryKey: ['GET', url],
|
||||
queryFn: () => callEndpoint(),
|
||||
});
|
||||
}
|
||||
|
||||
export function useOSMAPI({ address }: { address: string }) {
|
||||
const url = `https://nominatim.openstreetmap.org/search?addressdetails=1&format=jsonv2&limit=1&q=${address?.replaceAll(' ', '+')}`;
|
||||
const callEndpoint = async () => {
|
||||
|
||||
Reference in New Issue
Block a user