From 72ac81529449a678fb3fdaa500ac688234301e35 Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Thu, 26 Mar 2026 22:34:01 +0530 Subject: [PATCH] feat(weather): change to `freeipapi`, move `getApproxLocation` to actions --- src/components/WeatherWidget.tsx | 16 ++++------------ src/lib/actions.ts | 14 ++++++++++++++ src/lib/serverActions.ts | 1 + 3 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 src/lib/serverActions.ts diff --git a/src/components/WeatherWidget.tsx b/src/components/WeatherWidget.tsx index a7ebcffb..f96c5b10 100644 --- a/src/components/WeatherWidget.tsx +++ b/src/components/WeatherWidget.tsx @@ -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 { getApproxLocation } from '@/lib/actions'; const WeatherWidget = () => { const [data, setData] = useState({ @@ -15,17 +18,6 @@ const WeatherWidget = () => { 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 ( callback: (location: { latitude: number; diff --git a/src/lib/actions.ts b/src/lib/actions.ts index ceac7711..086853cd 100644 --- a/src/lib/actions.ts +++ b/src/lib/actions.ts @@ -20,3 +20,17 @@ export const getSuggestions = async (chatHistory: [string, string][]) => { 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, + }; +}; diff --git a/src/lib/serverActions.ts b/src/lib/serverActions.ts new file mode 100644 index 00000000..76b568fb --- /dev/null +++ b/src/lib/serverActions.ts @@ -0,0 +1 @@ +'use server'; \ No newline at end of file