import React, { useState, useEffect } from 'react'; import { applyIOMarketTheme, applyWhiteTheme, applyBlackTheme } from './theme'; import { exportSettings, importSettings } from './settingUtils'; // Import utility functions const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ({ closeSettings, accountName }) => { const getItemFromLocalStorage = (key: string) => { const item = localStorage.getItem(key); if (item) { try { return JSON.parse(item); // Attempt to parse the item } catch (e) { console.error(`Error parsing JSON for key "${key}":`, e); return false; // Return false if parsing fails } } return false; // Default to false if item is null or empty }; interface SettingsProps { closeSettings: () => void; accountName: string; handleLogout: () => void; // Add this line to accept handleLogout as a prop } // Active section const [activeSection, setActiveSection] = useState(() => localStorage.getItem('activeSection') || 'general'); // Language setting const [preferredLanguage, setPreferredLanguage] = useState(() => localStorage.getItem('preferredLanguage') || 'en'); // Currency setting const [preferredCurrency, setPreferredCurrency] = useState(() => localStorage.getItem('preferredCurrency') || 'usd'); // Date and time format settings const [dateFormat, setDateFormat] = useState(() => localStorage.getItem('dateFormat') || 'mm/dd/yyyy'); const [timeFormat, setTimeFormat] = useState(() => localStorage.getItem('timeFormat') || '12-hour'); const [timeZone, setTimeZone] = useState(() => localStorage.getItem('timeZone') || 'GMT'); // Online AI and chat history settings const [selectedOption, setSelectedOption] = useState('Offline'); // Default to 'Offline' const [disableChatHistory, setDisableChatHistory] = useState(() => getItemFromLocalStorage('disableChatHistory')); const [disableAIMemory, setDisableAIMemory] = useState(() => getItemFromLocalStorage('disableAIMemory')); const [openSourceMode, setOpenSourceMode] = useState(() => getItemFromLocalStorage('openSourceMode')); // User credentials const [newName, setNewName] = useState(() => localStorage.getItem('newName') || ''); const [newEmail, setNewEmail] = useState(() => localStorage.getItem('newEmail') || ''); const [newPassword, setNewPassword] = useState(() => localStorage.getItem('newPassword') || ''); // Measurement setting const [preferredMeasurement, setPreferredMeasurement] = useState(() => localStorage.getItem('preferredMeasurement') || 'Metric'); // Theme settings const [backgroundColor, setBackgroundColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--background-color').trim()); const [textColor, setTextColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--text-color').trim()); const [inputBackgroundColor, setInputBackgroundColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--input-background-color').trim()); const [inputButtonColor, setInputButtonColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--input-button-color').trim()); const [inputButtonHoverColor, setInputButtonHoverColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--input-button-hover-color').trim()); const [userMessageBackgroundColor, setUserMessageBackgroundColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--user-message-background-color').trim()); const [userMessageTextColor, setUserMessageTextColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--user-message-text-color').trim()); const [aiMessageBackgroundColor, setAiMessageBackgroundColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--ai-message-background-color').trim()); const [aiMessageTextColor, setAiMessageTextColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--ai-message-text-color').trim()); const [buttonBackgroundColor, setButtonBackgroundColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--button-background-color').trim()); const [buttonHoverBackgroundColor, setButtonHoverBackgroundColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--button-hover-background-color').trim()); const [modelsBackgroundColor, setModelsBackgroundColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--models-background-color').trim()); const [historyBackgroundColor, setHistoryBackgroundColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--history-background-color').trim()); const [leftPanelBackgroundColor, setLeftPanelBackgroundColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--left-panel-background-color').trim()); const [conversationBackgroundColor, setConversationBackgroundColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--conversation-background-color').trim()); const [popUpTextColor, setPopUpTextColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--pop-up-text').trim()); const [inputBorderColor, setInputBorderColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--input-border-color').trim()); const [fontFamily, setFontFamily] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--font-family').trim()); const [fontSize, setFontSize] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--font-size').trim()); const [burgerMenu, setBurgerMenu] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--burger-menu-background-color').trim()); // Theme selection const [selectedTheme, setSelectedTheme] = useState(() => localStorage.getItem('selectedTheme') || 'default'); // API Keys const [laPlateforme, setLaPlateforme] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-la-plateforme').trim()); const [openAI, setOpenAI] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-cheap-openai').trim()); const [anthropic, setAnthropic] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-cheap-anthropic').trim()); const [google, setGoogle] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-cheap-google').trim()); const [isLoggedIn, setIsLoggedIn] = useState(false); const handleLogout = () => { setIsLoggedIn(false); localStorage.removeItem('accountName'); localStorage.removeItem('accountEmail'); localStorage.removeItem('accountPassword'); }; // Effect hooks to update localStorage whenever any state changes useEffect(() => { const settings = { activeSection, preferredLanguage, preferredCurrency, dateFormat, timeFormat, timeZone, selectedOption, disableChatHistory, disableAIMemory, openSourceMode, newName, newEmail, newPassword, preferredMeasurement, backgroundColor, textColor, inputBackgroundColor, inputButtonColor, inputButtonHoverColor, userMessageBackgroundColor, userMessageTextColor, aiMessageBackgroundColor, aiMessageTextColor, buttonBackgroundColor, buttonHoverBackgroundColor, modelsBackgroundColor, historyBackgroundColor, leftPanelBackgroundColor, conversationBackgroundColor, popUpTextColor, inputBorderColor, fontFamily, fontSize, burgerMenu, selectedTheme, laPlateforme, openAI, anthropic, google, }; // Update local storage for (const [key, value] of Object.entries(settings)) { if (typeof value === 'boolean') { localStorage.setItem(key, JSON.stringify(value)); } else { localStorage.setItem(key, value); } } }, [ activeSection, preferredLanguage, preferredCurrency, dateFormat, timeFormat, timeZone, selectedOption, disableChatHistory, disableAIMemory, openSourceMode, newName, newEmail, newPassword, preferredMeasurement, backgroundColor, textColor, inputBackgroundColor, inputButtonColor, inputButtonHoverColor, userMessageBackgroundColor, userMessageTextColor, aiMessageBackgroundColor, aiMessageTextColor, buttonBackgroundColor, buttonHoverBackgroundColor, modelsBackgroundColor, historyBackgroundColor, leftPanelBackgroundColor, conversationBackgroundColor, popUpTextColor, inputBorderColor, fontFamily, fontSize, burgerMenu, selectedTheme, laPlateforme, openAI, anthropic, google, ]); useEffect(() => { const savedOption = localStorage.getItem('radioSelection'); if (savedOption) { setSelectedOption(savedOption); // Set saved selection } }, []); const handleRadioChange = (newValue: string) => { setSelectedOption(newValue); // Update the state with the selected option localStorage.setItem('radioSelection', newValue); // Save the selection for persistence }; // Apply imported settings to the CSS variables const applySettings = (settings: any) => { if (settings.backgroundColor) { setBackgroundColor(settings.backgroundColor); document.documentElement.style.setProperty('--background-color', settings.backgroundColor); } if (settings.textColor) { setTextColor(settings.textColor); document.documentElement.style.setProperty('--text-color', settings.textColor); } if (settings.inputBackgroundColor) { setInputBackgroundColor(settings.inputBackgroundColor); document.documentElement.style.setProperty('--input-background-color', settings.inputBackgroundColor); } if (settings.inputButtonColor) { setInputButtonColor(settings.inputButtonColor); document.documentElement.style.setProperty('--input-button-color', settings.inputButtonColor); } if (settings.inputButtonHoverColor) { setInputButtonHoverColor(settings.inputButtonHoverColor); document.documentElement.style.setProperty('--input-button-hover-color', settings.inputButtonHoverColor); } if (settings.userMessageBackgroundColor) { setUserMessageBackgroundColor(settings.userMessageBackgroundColor); document.documentElement.style.setProperty('--user-message-background-color', settings.userMessageBackgroundColor); } if (settings.userMessageTextColor) { setUserMessageTextColor(settings.userMessageTextColor); document.documentElement.style.setProperty('--user-message-text-color', settings.userMessageTextColor); } if (settings.aiMessageBackgroundColor) { setAiMessageBackgroundColor(settings.aiMessageBackgroundColor); document.documentElement.style.setProperty('--ai-message-background-color', settings.aiMessageBackgroundColor); } if (settings.aiMessageTextColor) { setAiMessageTextColor(settings.aiMessageTextColor); document.documentElement.style.setProperty('--ai-message-text-color', settings.aiMessageTextColor); } if (settings.buttonBackgroundColor) { setButtonBackgroundColor(settings.buttonBackgroundColor); document.documentElement.style.setProperty('--button-background-color', settings.buttonBackgroundColor); } if (settings.buttonHoverBackgroundColor) { setButtonHoverBackgroundColor(settings.buttonHoverBackgroundColor); document.documentElement.style.setProperty('--button-hover-background-color', settings.buttonHoverBackgroundColor); } if (settings.modelsBackgroundColor) { setModelsBackgroundColor(settings.modelsBackgroundColor); document.documentElement.style.setProperty('--models-background-color', settings.modelsBackgroundColor); } if (settings.historyBackgroundColor) { setHistoryBackgroundColor(settings.historyBackgroundColor); document.documentElement.style.setProperty('--history-background-color', settings.historyBackgroundColor); } if (settings.leftPanelBackgroundColor) { setLeftPanelBackgroundColor(settings.leftPanelBackgroundColor); document.documentElement.style.setProperty('--left-panel-background-color', settings.leftPanelBackgroundColor); } if (settings.conversationBackgroundColor) { setConversationBackgroundColor(settings.conversationBackgroundColor); document.documentElement.style.setProperty('--conversation-background-color', settings.conversationBackgroundColor); } if (settings.popUpTextColor) { setPopUpTextColor(settings.popUpTextColor); document.documentElement.style.setProperty('--pop-up-text', settings.popUpTextColor); } if (settings.inputBorderColor) { setInputBorderColor(settings.inputBorderColor); document.documentElement.style.setProperty('--input-border-color', settings.inputBorderColor); } if (settings.fontFamily) { setFontFamily(settings.fontFamily); document.documentElement.style.setProperty('--font-family', settings.fontFamily); } if (settings.fontSize) { setFontSize(settings.fontSize); document.documentElement.style.setProperty('--font-size', settings.fontSize); } if (settings.burgerMenu) { setBurgerMenu(settings.fontSize); document.documentElement.style.setProperty('--burger-menu-background-color:', settings.burgerMenu); } }; // Render settings content based on the active section const renderSettingsContent = () => { switch (activeSection) { case 'general': return (
Disable Options:
These options are deactivated because you are in FOSS mode.
)}After changing the preferred settings, please reload the website so it can update itself properly.
Select Theme
Font Size
{ const newSize = `${e.target.value}px`; setFontSize(newSize); document.documentElement.style.setProperty('--font-size', newSize); }} /> {fontSize}Background Color
{ const newColor = e.target.value; setBackgroundColor(newColor); document.documentElement.style.setProperty('--background-color', newColor); }} />Text Color
{ const newColor = e.target.value; setTextColor(newColor); document.documentElement.style.setProperty('--text-color', newColor); }} />Input Background Color
{ const newColor = e.target.value; setInputBackgroundColor(newColor); document.documentElement.style.setProperty('--input-background-color', newColor); }} />Input Button Color
{ const newColor = e.target.value; setInputButtonColor(newColor); document.documentElement.style.setProperty('--input-button-color', newColor); }} />Input Button Hover Color
{ const newColor = e.target.value; setInputButtonHoverColor(newColor); document.documentElement.style.setProperty('--input-button-hover-color', newColor); }} />User Message Background Color
{ const newColor = e.target.value; setUserMessageBackgroundColor(newColor); document.documentElement.style.setProperty('--user-message-background-color', newColor); }} />User Message Text Color
{ const newColor = e.target.value; setUserMessageTextColor(newColor); document.documentElement.style.setProperty('--user-message-text-color', newColor); }} />AI Message Background Color
{ const newColor = e.target.value; setAiMessageBackgroundColor(newColor); document.documentElement.style.setProperty('--ai-message-background-color', newColor); }} />AI Message Text Color
{ const newColor = e.target.value; setAiMessageTextColor(newColor); document.documentElement.style.setProperty('--ai-message-text-color', newColor); }} />Button Background Color
{ const newColor = e.target.value; setButtonBackgroundColor(newColor); document.documentElement.style.setProperty('--button-background-color', newColor); }} />Button Hover Background Color
{ const newColor = e.target.value; setButtonHoverBackgroundColor(newColor); document.documentElement.style.setProperty('--button-hover-background-color', newColor); }} />Models Background Color
{ const newColor = e.target.value; setModelsBackgroundColor(newColor); document.documentElement.style.setProperty('--models-background-color', newColor); }} />History Background Color
{ const newColor = e.target.value; setHistoryBackgroundColor(newColor); document.documentElement.style.setProperty('--history-background-color', newColor); }} />Left Panel Background Color
{ const newColor = e.target.value; setLeftPanelBackgroundColor(newColor); document.documentElement.style.setProperty('--left-panel-background-color', newColor); }} />Conversation Background Color
{ const newColor = e.target.value; setConversationBackgroundColor(newColor); document.documentElement.style.setProperty('--conversation-background-color', newColor); }} />Pop-up Text Color
{ const newColor = e.target.value; setPopUpTextColor(newColor); document.documentElement.style.setProperty('--pop-up-text', newColor); }} />Burger Menu Color
{ const newColor = e.target.value; setBurgerMenu(newColor); document.documentElement.style.setProperty('--burger-menu-background-color', newColor); }} />Input Border Color
{ const newColor = e.target.value; setInputBorderColor(newColor); document.documentElement.style.setProperty('--input-border-color', newColor); }} />Font Family