From 1c1368272138ea65c277115c15a82288100ae62f Mon Sep 17 00:00:00 2001 From: josh <144584931+dancer@users.noreply.github.com> Date: Thu, 9 Oct 2025 19:28:04 +0100 Subject: [PATCH] chore: updated weather tool (#1269) --- components/weather.tsx | 146 +++++++++++++++++++++++++----------- lib/ai/tools/get-weather.ts | 63 ++++++++++++++-- 2 files changed, 159 insertions(+), 50 deletions(-) diff --git a/components/weather.tsx b/components/weather.tsx index 38ccc05..d4e7234 100644 --- a/components/weather.tsx +++ b/components/weather.tsx @@ -4,6 +4,32 @@ import cx from "classnames"; import { format, isWithinInterval } from "date-fns"; import { useEffect, useState } from "react"; +const SunIcon = ({ size = 40 }: { size?: number }) => ( + +); + +const MoonIcon = ({ size = 40 }: { size?: number }) => ( + +); + +const CloudIcon = ({ size = 24 }: { size?: number }) => ( + +); + type WeatherAtLocation = { latitude: number; longitude: number; @@ -12,6 +38,7 @@ type WeatherAtLocation = { timezone: string; timezone_abbreviation: string; elevation: number; + cityName?: string; current_units: { time: string; interval: string; @@ -233,12 +260,10 @@ export function Weather({ const hoursToShow = isMobile ? 5 : 6; - // Find the index of the current time or the next closest time const currentTimeIndex = weatherAtLocation.hourly.time.findIndex( (time) => new Date(time) >= new Date(weatherAtLocation.current.time) ); - // Slice the arrays to get the desired number of items const displayTimes = weatherAtLocation.hourly.time.slice( currentTimeIndex, currentTimeIndex + hoursToShow @@ -248,63 +273,96 @@ export function Weather({ currentTimeIndex + hoursToShow ); + const location = weatherAtLocation.cityName || + `${weatherAtLocation.latitude?.toFixed(1)}°, ${weatherAtLocation.longitude?.toFixed(1)}°`; + return (