Skip to content

Commit 5901a96

Browse files
authored
Merge pull request #934 from PSYEONE/no-ads
Added ability to remove the widgets in the front empty page of the search. Specifically the Weather and News widget.
2 parents 9934c1d + 6150784 commit 5901a96

File tree

4 files changed

+81
-7
lines changed

4 files changed

+81
-7
lines changed

src/components/EmptyChat.tsx

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
1+
'use client';
2+
3+
import { useEffect, useState } from 'react';
14
import { Settings } from 'lucide-react';
25
import EmptyChatMessageInput from './EmptyChatMessageInput';
36
import { File } from './ChatWindow';
47
import Link from 'next/link';
58
import WeatherWidget from './WeatherWidget';
69
import NewsArticleWidget from './NewsArticleWidget';
710
import SettingsButtonMobile from '@/components/Settings/SettingsButtonMobile';
11+
import {
12+
getShowNewsWidget,
13+
getShowWeatherWidget,
14+
} from '@/lib/config/clientRegistry';
815

916
const EmptyChat = () => {
17+
const [showWeather, setShowWeather] = useState(() =>
18+
typeof window !== 'undefined' ? getShowWeatherWidget() : true,
19+
);
20+
const [showNews, setShowNews] = useState(() =>
21+
typeof window !== 'undefined' ? getShowNewsWidget() : true,
22+
);
23+
24+
useEffect(() => {
25+
const updateWidgetVisibility = () => {
26+
setShowWeather(getShowWeatherWidget());
27+
setShowNews(getShowNewsWidget());
28+
};
29+
30+
updateWidgetVisibility();
31+
32+
window.addEventListener('client-config-changed', updateWidgetVisibility);
33+
window.addEventListener('storage', updateWidgetVisibility);
34+
35+
return () => {
36+
window.removeEventListener(
37+
'client-config-changed',
38+
updateWidgetVisibility,
39+
);
40+
window.removeEventListener('storage', updateWidgetVisibility);
41+
};
42+
}, []);
43+
1044
return (
1145
<div className="relative">
1246
<div className="absolute w-full flex flex-row items-center justify-end mr-5 mt-5">
@@ -19,14 +53,20 @@ const EmptyChat = () => {
1953
</h2>
2054
<EmptyChatMessageInput />
2155
</div>
22-
<div className="flex flex-col w-full gap-4 mt-2 sm:flex-row sm:justify-center">
23-
<div className="flex-1 w-full">
24-
<WeatherWidget />
56+
{(showWeather || showNews) && (
57+
<div className="flex flex-col w-full gap-4 mt-2 sm:flex-row sm:justify-center">
58+
{showWeather && (
59+
<div className="flex-1 w-full">
60+
<WeatherWidget />
61+
</div>
62+
)}
63+
{showNews && (
64+
<div className="flex-1 w-full">
65+
<NewsArticleWidget />
66+
</div>
67+
)}
2568
</div>
26-
<div className="flex-1 w-full">
27-
<NewsArticleWidget />
28-
</div>
29-
</div>
69+
)}
3070
</div>
3171
</div>
3272
);

src/components/Settings/SettingsField.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import { useTheme } from 'next-themes';
1212
import { Loader2 } from 'lucide-react';
1313
import { Switch } from '@headlessui/react';
1414

15+
const emitClientConfigChanged = () => {
16+
if (typeof window !== 'undefined') {
17+
window.dispatchEvent(new Event('client-config-changed'));
18+
}
19+
};
20+
1521
const SettingsSelect = ({
1622
field,
1723
value,
@@ -35,6 +41,7 @@ const SettingsSelect = ({
3541
if (field.key === 'theme') {
3642
setTheme(newValue);
3743
}
44+
emitClientConfigChanged();
3845
} else {
3946
const res = await fetch('/api/config', {
4047
method: 'POST',
@@ -106,6 +113,7 @@ const SettingsInput = ({
106113
try {
107114
if (field.scope === 'client') {
108115
localStorage.setItem(field.key, newValue);
116+
emitClientConfigChanged();
109117
} else {
110118
const res = await fetch('/api/config', {
111119
method: 'POST',
@@ -182,6 +190,7 @@ const SettingsTextarea = ({
182190
try {
183191
if (field.scope === 'client') {
184192
localStorage.setItem(field.key, newValue);
193+
emitClientConfigChanged();
185194
} else {
186195
const res = await fetch('/api/config', {
187196
method: 'POST',
@@ -258,6 +267,7 @@ const SettingsSwitch = ({
258267
try {
259268
if (field.scope === 'client') {
260269
localStorage.setItem(field.key, String(newValue));
270+
emitClientConfigChanged();
261271
} else {
262272
const res = await fetch('/api/config', {
263273
method: 'POST',

src/lib/config/clientRegistry.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ export const getAutoMediaSearch = () =>
1111

1212
export const getSystemInstructions = () =>
1313
getClientConfig('systemInstructions', '');
14+
15+
export const getShowWeatherWidget = () =>
16+
getClientConfig('showWeatherWidget', 'true') === 'true';
17+
18+
export const getShowNewsWidget = () =>
19+
getClientConfig('showNewsWidget', 'true') === 'true';

src/lib/config/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ class ConfigManager {
6969
default: true,
7070
scope: 'client',
7171
},
72+
{
73+
name: 'Show weather widget',
74+
key: 'showWeatherWidget',
75+
type: 'switch',
76+
required: false,
77+
description: 'Display the weather card on the home screen.',
78+
default: true,
79+
scope: 'client',
80+
},
81+
{
82+
name: 'Show news widget',
83+
key: 'showNewsWidget',
84+
type: 'switch',
85+
required: false,
86+
description: 'Display the recent news card on the home screen.',
87+
default: true,
88+
scope: 'client',
89+
},
7290
],
7391
personalization: [
7492
{

0 commit comments

Comments
 (0)