Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ We'd also like to thank the following partners for their generous support:

<table>
<tr>
<td>
<td width="100" align="center">
<a href="https://dashboard.exa.ai" target="_blank">
<img src=".assets/sponsers/exa.png" alt="Exa" style="max-width: 8rem; max-height: 8rem; border-radius: .75rem;" />
<img src=".assets/sponsers/exa.png" alt="Exa" width="80" height="80" style="border-radius: .75rem;" />
</a>
</td>
<td>
Expand Down
54 changes: 47 additions & 7 deletions src/components/EmptyChat.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
'use client';

import { useEffect, useState } from 'react';
import { Settings } from 'lucide-react';
import EmptyChatMessageInput from './EmptyChatMessageInput';
import { File } from './ChatWindow';
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(() =>
typeof window !== 'undefined' ? getShowWeatherWidget() : true,
);
const [showNews, setShowNews] = useState(() =>
typeof window !== 'undefined' ? getShowNewsWidget() : 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 (
<div className="relative">
<div className="absolute w-full flex flex-row items-center justify-end mr-5 mt-5">
Expand All @@ -19,14 +53,20 @@ const EmptyChat = () => {
</h2>
<EmptyChatMessageInput />
</div>
<div className="flex flex-col w-full gap-4 mt-2 sm:flex-row sm:justify-center">
<div className="flex-1 w-full">
<WeatherWidget />
{(showWeather || showNews) && (
<div className="flex flex-col w-full gap-4 mt-2 sm:flex-row sm:justify-center">
{showWeather && (
<div className="flex-1 w-full">
<WeatherWidget />
</div>
)}
{showNews && (
<div className="flex-1 w-full">
<NewsArticleWidget />
</div>
)}
</div>
<div className="flex-1 w-full">
<NewsArticleWidget />
</div>
</div>
)}
</div>
</div>
);
Expand Down
10 changes: 10 additions & 0 deletions src/components/Settings/SettingsField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -35,6 +41,7 @@ const SettingsSelect = ({
if (field.key === 'theme') {
setTheme(newValue);
}
emitClientConfigChanged();
} else {
const res = await fetch('/api/config', {
method: 'POST',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions src/lib/config/clientRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
18 changes: 18 additions & 0 deletions src/lib/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down