feat(weather): change to freeipapi, move getApproxLocation to actions

This commit is contained in:
ItzCrazyKns
2026-03-26 22:34:01 +05:30
parent d16b7e271a
commit 72ac815294
3 changed files with 19 additions and 12 deletions

View File

@@ -1,5 +1,8 @@
import { Cloud, Sun, CloudRain, CloudSnow, Wind } from 'lucide-react'; 'use client';
import { Wind } from 'lucide-react';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { getApproxLocation } from '@/lib/actions';
const WeatherWidget = () => { const WeatherWidget = () => {
const [data, setData] = useState({ const [data, setData] = useState({
@@ -15,17 +18,6 @@ const WeatherWidget = () => {
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const getApproxLocation = async () => {
const res = await fetch('https://ipwhois.app/json/');
const data = await res.json();
return {
latitude: data.latitude,
longitude: data.longitude,
city: data.city,
};
};
const getLocation = async ( const getLocation = async (
callback: (location: { callback: (location: {
latitude: number; latitude: number;

View File

@@ -20,3 +20,17 @@ export const getSuggestions = async (chatHistory: [string, string][]) => {
return data.suggestions; return data.suggestions;
}; };
export const getApproxLocation = async () => {
const res = await fetch('https://free.freeipapi.com/api/json', {
method: 'GET',
});
const data = await res.json();
return {
latitude: data.latitude,
longitude: data.longitude,
city: data.cityName,
};
};

1
src/lib/serverActions.ts Normal file
View File

@@ -0,0 +1 @@
'use server';