mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2026-03-28 23:44:25 +00:00
feat(weather): change to freeipapi, move getApproxLocation to actions
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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
1
src/lib/serverActions.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
'use server';
|
||||||
Reference in New Issue
Block a user