From 3005b379cfc346d7842e6d7a85d72f6d21e02143 Mon Sep 17 00:00:00 2001 From: PSYEONE Date: Fri, 28 Nov 2025 11:59:53 +0000 Subject: [PATCH] Added functionality for hiding weather and news widgets --- src/components/EmptyChat.tsx | 50 +++++++++++++++++++---- src/components/Settings/SettingsField.tsx | 10 +++++ src/lib/config/clientRegistry.ts | 6 +++ src/lib/config/index.ts | 18 ++++++++ 4 files changed, 77 insertions(+), 7 deletions(-) diff --git a/src/components/EmptyChat.tsx b/src/components/EmptyChat.tsx index d9b6686..53ec46a 100644 --- a/src/components/EmptyChat.tsx +++ b/src/components/EmptyChat.tsx @@ -1,3 +1,6 @@ +"use client"; + +import { useEffect, useState } from 'react'; import { Settings } from 'lucide-react'; import EmptyChatMessageInput from './EmptyChatMessageInput'; import { File } from './ChatWindow'; @@ -5,8 +8,35 @@ import Link from 'next/link'; import WeatherWidget from './WeatherWidget'; import NewsArticleWidget from './NewsArticleWidget'; import SettingsButtonMobile from '@/components/Settings/SettingsButtonMobile'; +import { + getShowNewsWidget, + getShowWeatherWidget, +} from '@/lib/config/clientRegistry'; const EmptyChat = () => { + const [showWeather, setShowWeather] = useState(true); + const [showNews, setShowNews] = useState(true); + + useEffect(() => { + const updateWidgetVisibility = () => { + setShowWeather(getShowWeatherWidget()); + setShowNews(getShowNewsWidget()); + }; + + updateWidgetVisibility(); + + window.addEventListener('client-config-changed', updateWidgetVisibility); + window.addEventListener('storage', updateWidgetVisibility); + + return () => { + window.removeEventListener( + 'client-config-changed', + updateWidgetVisibility, + ); + window.removeEventListener('storage', updateWidgetVisibility); + }; + }, []); + return (
@@ -19,14 +49,20 @@ const EmptyChat = () => {
-
-
- + {(showWeather || showNews) && ( +
+ {showWeather && ( +
+ +
+ )} + {showNews && ( +
+ +
+ )}
-
- -
-
+ )}
); diff --git a/src/components/Settings/SettingsField.tsx b/src/components/Settings/SettingsField.tsx index 55aa640..843ce7c 100644 --- a/src/components/Settings/SettingsField.tsx +++ b/src/components/Settings/SettingsField.tsx @@ -12,6 +12,12 @@ import { useTheme } from 'next-themes'; import { Loader2 } from 'lucide-react'; import { Switch } from '@headlessui/react'; +const emitClientConfigChanged = () => { + if (typeof window !== 'undefined') { + window.dispatchEvent(new Event('client-config-changed')); + } +}; + const SettingsSelect = ({ field, value, @@ -35,6 +41,7 @@ const SettingsSelect = ({ if (field.key === 'theme') { setTheme(newValue); } + emitClientConfigChanged(); } else { const res = await fetch('/api/config', { method: 'POST', @@ -106,6 +113,7 @@ const SettingsInput = ({ try { if (field.scope === 'client') { localStorage.setItem(field.key, newValue); + emitClientConfigChanged(); } else { const res = await fetch('/api/config', { method: 'POST', @@ -182,6 +190,7 @@ const SettingsTextarea = ({ try { if (field.scope === 'client') { localStorage.setItem(field.key, newValue); + emitClientConfigChanged(); } else { const res = await fetch('/api/config', { method: 'POST', @@ -258,6 +267,7 @@ const SettingsSwitch = ({ try { if (field.scope === 'client') { localStorage.setItem(field.key, String(newValue)); + emitClientConfigChanged(); } else { const res = await fetch('/api/config', { method: 'POST', diff --git a/src/lib/config/clientRegistry.ts b/src/lib/config/clientRegistry.ts index 7c8fc24..28d0951 100644 --- a/src/lib/config/clientRegistry.ts +++ b/src/lib/config/clientRegistry.ts @@ -11,3 +11,9 @@ export const getAutoMediaSearch = () => export const getSystemInstructions = () => getClientConfig('systemInstructions', ''); + +export const getShowWeatherWidget = () => + getClientConfig('showWeatherWidget', 'true') === 'true'; + +export const getShowNewsWidget = () => + getClientConfig('showNewsWidget', 'true') === 'true'; diff --git a/src/lib/config/index.ts b/src/lib/config/index.ts index 9b69c8a..4830538 100644 --- a/src/lib/config/index.ts +++ b/src/lib/config/index.ts @@ -69,6 +69,24 @@ class ConfigManager { default: true, scope: 'client', }, + { + name: 'Show weather widget', + key: 'showWeatherWidget', + type: 'switch', + required: false, + description: 'Display the weather card on the home screen.', + default: true, + scope: 'client', + }, + { + name: 'Show news widget', + key: 'showNewsWidget', + type: 'switch', + required: false, + description: 'Display the recent news card on the home screen.', + default: true, + scope: 'client', + }, ], personalization: [ {