From 11d24936c740bc5aef535f032f95f187f899911d Mon Sep 17 00:00:00 2001 From: Samuel Dockery Date: Sun, 10 Aug 2025 10:03:54 -0700 Subject: [PATCH] feat: add weather toggle in settings --- src/app/settings/page.tsx | 47 ++++++++++++++++++++++++++++++++ src/components/EmptyChat.tsx | 15 ++++++++-- src/components/WeatherWidget.tsx | 1 + 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/app/settings/page.tsx b/src/app/settings/page.tsx index 1b13c9c..6fe0911 100644 --- a/src/app/settings/page.tsx +++ b/src/app/settings/page.tsx @@ -27,6 +27,7 @@ interface SettingsType { customOpenaiApiKey: string; customOpenaiApiUrl: string; customOpenaiModelName: string; + weatherWidgetEnabled?: boolean; } interface InputProps extends React.InputHTMLAttributes { @@ -151,6 +152,7 @@ const Page = () => { const [measureUnit, setMeasureUnit] = useState<'Imperial' | 'Metric'>( 'Metric', ); + const [weatherWidgetEnabled, setWeatherWidgetEnabled] = useState(true); const [savingStates, setSavingStates] = useState>({}); useEffect(() => { @@ -217,6 +219,12 @@ const Page = () => { localStorage.getItem('measureUnit')! as 'Imperial' | 'Metric', ); + setWeatherWidgetEnabled( + localStorage.getItem('weatherWidgetEnabled') === null + ? true + : localStorage.getItem('weatherWidgetEnabled') === 'true', + ); + setIsLoading(false); }; @@ -377,6 +385,8 @@ const Page = () => { localStorage.setItem('systemInstructions', value); } else if (key === 'measureUnit') { localStorage.setItem('measureUnit', value.toString()); + } else if (key === 'weatherWidgetEnabled') { + localStorage.setItem('weatherWidgetEnabled', value.toString()); } } catch (err) { console.error('Failed to save:', err); @@ -454,6 +464,43 @@ const Page = () => { ]} /> + +
+

+ Show Weather Widget +

+
+
+
+ +
+
+

Weather Widget

+

+ Show the weather widget on the Home Page +

+
+
+ { + setWeatherWidgetEnabled(checked); + saveConfig('weatherWidgetEnabled', checked); + }} + className={cn( + weatherWidgetEnabled ? 'bg-[#24A0ED]' : 'bg-light-200 dark:bg-dark-200', + 'relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none', + )} + > + + +
+
diff --git a/src/components/EmptyChat.tsx b/src/components/EmptyChat.tsx index 0eb76ac..a4abe1d 100644 --- a/src/components/EmptyChat.tsx +++ b/src/components/EmptyChat.tsx @@ -1,4 +1,6 @@ +'use client'; import { Settings } from 'lucide-react'; +import { useEffect, useState } from 'react'; import EmptyChatMessageInput from './EmptyChatMessageInput'; import { File } from './ChatWindow'; import Link from 'next/link'; @@ -26,6 +28,11 @@ const EmptyChat = ({ files: File[]; setFiles: (files: File[]) => void; }) => { + const [weatherEnabled, setWeatherEnabled] = useState(true); + useEffect(() => { + const item = localStorage.getItem('weatherWidgetEnabled'); + setWeatherEnabled(item === null ? true : item === 'true'); + }, []); return (
@@ -51,9 +58,11 @@ const EmptyChat = ({ />
-
- -
+ {weatherEnabled && ( +
+ +
+ )}
diff --git a/src/components/WeatherWidget.tsx b/src/components/WeatherWidget.tsx index 8eaf871..ad9b2cf 100644 --- a/src/components/WeatherWidget.tsx +++ b/src/components/WeatherWidget.tsx @@ -1,3 +1,4 @@ +'use client'; import { Cloud, Sun, CloudRain, CloudSnow, Wind } from 'lucide-react'; import { useEffect, useState } from 'react';