MY brain is fried and fired || Patrick helped me on the drpodown issues --> none left for the moment #61

Merged
Patrick_Pluto merged 2 commits from sageTheDm/interstellar_ai:main into main 2024-09-27 14:58:56 +02:00
4 changed files with 130 additions and 65 deletions

View file

@ -0,0 +1,15 @@
// getLocalStorageData.ts
export const getAllLocalStorageItems = (): Record<string, string | null> => {
const allData: Record<string, string | null> = {};
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key) {
const value = localStorage.getItem(key);
allData[key] = value;
}
}
return allData;
};

View file

@ -2,16 +2,9 @@ import React, { useState, useEffect } from 'react';
// Define the available model options // Define the available model options
const modelDropdown = { const modelDropdown = {
offlineModels: [ offlineWithoutFoss: ['Offline Fast', 'Offline Slow'],
'Offline Fast', offlineFoss: ['Offline Fast (FOSS)', 'Offline Slow (FOSS)'],
'Offline Fast (FOSS)', onlineWithoutFoss: [
'Offline Slow',
'Offline Slow (FOSS)',
],
onlineModels: [
'Online (La Plateforme)',
'Online (FOSS) (La Plateforme)',
'Online Cheap (OpenAI)', 'Online Cheap (OpenAI)',
'Online Expensive (OpenAI)', 'Online Expensive (OpenAI)',
'Online Cheap (Anthropic)', 'Online Cheap (Anthropic)',
@ -19,21 +12,17 @@ const modelDropdown = {
'Online Cheap (Google)', 'Online Cheap (Google)',
'Online Expensive (Google)', 'Online Expensive (Google)',
], ],
onlineFoss: ['Online (FOSS) (La Plateforme)'],
fossModels: [
'Offline Fast (FOSS)',
'Offline Slow (FOSS)',
'Online (FOSS) (La Plateforme)',
],
}; };
const Models: React.FC = () => { const Models: React.FC = () => {
// Initialize state with value from localStorage or default to '' // Initialize state with value from localStorage or default to ''
const [radioSelection, setRadioSelection] = useState(''); const [selectedModel, setSelectedModel] = useState('');
const radioSelection = localStorage.getItem('radioSelection')
useEffect(() => { useEffect(() => {
const handleStorageChange = () => { const handleStorageChange = () => {
setRadioSelection(localStorage.getItem('radioSelection') || ''); setSelectedModel(localStorage.getItem('selectedModel') || '');
}; };
handleStorageChange(); handleStorageChange();
@ -48,7 +37,7 @@ const Models: React.FC = () => {
const handleModelChange = (event: React.ChangeEvent<HTMLSelectElement>) => { const handleModelChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
const newModel = event.target.value; const newModel = event.target.value;
setRadioSelection(newModel); setSelectedModel(newModel);
localStorage.setItem('radioSelection', newModel); // Update localStorage directly localStorage.setItem('radioSelection', newModel); // Update localStorage directly
}; };
@ -57,22 +46,55 @@ const Models: React.FC = () => {
let models = []; let models = [];
switch (radioSelection) { switch (radioSelection) {
case 'Offline': case 'Offline':
models = modelDropdown.offlineModels; // Show only offline models models = [
...modelDropdown.onlineWithoutFoss,
...modelDropdown.onlineFoss,
]; // Show only offline models without FOSS
break; break;
case 'AI Online': case 'Offline (FOSS)':
models = modelDropdown.onlineModels; // Show only online models models = [
...modelDropdown.onlineFoss,
]; // Show only offline models with FOSS
break; break;
case 'FOSS': case 'Online':
models = modelDropdown.fossModels; // Show only FOSS models models = [
...modelDropdown.offlineWithoutFoss,
...modelDropdown.offlineFoss,
]; // Show only online models without FOSS
break;
case 'Online (FOSS)':
models = [
...modelDropdown.offlineFoss,
]; // Show only online models with FOSS
break;
case 'None':
models = [
...modelDropdown.offlineWithoutFoss,
...modelDropdown.offlineFoss,
...modelDropdown.onlineWithoutFoss,
...modelDropdown.onlineFoss,
]; // Show all models if nothing matches
break;
case 'None (FOSS)':
models = [
...modelDropdown.offlineFoss,
...modelDropdown.onlineFoss,
]; // Show all models if nothing matches
break; break;
default: default:
models = [...modelDropdown.offlineModels, ...modelDropdown.onlineModels, ...modelDropdown.fossModels]; // Show all models if nothing matches models = [
...modelDropdown.offlineWithoutFoss,
...modelDropdown.offlineFoss,
...modelDropdown.onlineWithoutFoss,
...modelDropdown.onlineFoss,
]; // Show all models if nothing matches
break; break;
} }
return Array.from(new Set(models)); // Remove duplicates using Set return Array.from(new Set(models)); // Remove duplicates using Set
})(); })();
const isOfflineModel = (model: string) => modelDropdown.offlineModels.includes(model); const isOfflineModel = (model: string) =>
modelDropdown.offlineWithoutFoss.includes(model) || modelDropdown.offlineFoss.includes(model);
return ( return (
<div className="model-background"> <div className="model-background">
@ -84,7 +106,7 @@ const Models: React.FC = () => {
{/* Model Selection Dropdown */} {/* Model Selection Dropdown */}
<div className="model-dropdown"> <div className="model-dropdown">
<label htmlFor="model-select">Select AI Model:</label> <label htmlFor="model-select">Select AI Model:</label>
<select id="model-select" value={radioSelection} onChange={handleModelChange}> <select id="model-select" value={selectedModel} onChange={handleModelChange}>
{filteredModels.map((model) => ( {filteredModels.map((model) => (
<option key={model} value={model}> <option key={model} value={model}>
{model} {model}
@ -93,16 +115,19 @@ const Models: React.FC = () => {
</select> </select>
</div> </div>
{/* Model Grid with Cards */} {/* Model Grid with Cards */}
<div className="grid"> <div className="grid">
{['Code', 'Math', 'Language', 'Character', 'Finance', 'Weather', 'Time', 'Image', 'Custom1', 'Custom2'].map((category) => ( {['Code', 'Math', 'Language', 'Character', 'Finance', 'Weather', 'Time', 'Image', 'Custom1', 'Custom2'].map(
<button key={category} className={`${category.toLowerCase()}-model model-box`}> (category) => (
<div className="overlay"> <button key={category} className={`${category.toLowerCase()}-model model-box`}>
<h3>{category}</h3> <div className="overlay">
{isOfflineModel(radioSelection) && <img src="/img/nowifi.svg" alt="No Wi-Fi" />} <h3>{category}</h3>
</div> {isOfflineModel(selectedModel) && <img src="/img/nowifi.svg" alt="No Wi-Fi" />}
</button> </div>
))} </button>
)
)}
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,6 +1,7 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { applyIOMarketTheme, applyWhiteTheme, applyBlackTheme } from './theme'; import { applyIOMarketTheme, applyWhiteTheme, applyBlackTheme } from './theme';
import { exportSettings, importSettings } from './settingUtils'; // Import utility functions import { exportSettings, importSettings } from './settingUtils'; // Import utility functions
import { getAllLocalStorageItems } from '../backend/GetLocalStorage';
const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ({ closeSettings, accountName }) => { const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ({ closeSettings, accountName }) => {
@ -196,6 +197,9 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
const handleRadioChange = (newValue: string) => { const handleRadioChange = (newValue: string) => {
setSelectedOption(newValue); // Update the state with the selected option setSelectedOption(newValue); // Update the state with the selected option
if (openSourceMode){
newValue += " (FOSS)"
}
localStorage.setItem('radioSelection', newValue); // Save the selection for persistence localStorage.setItem('radioSelection', newValue); // Save the selection for persistence
}; };
@ -415,34 +419,36 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
{/* AI Mode Radio Options */} {/* AI Mode Radio Options */}
<div className="settings-option"> <div className="settings-option">
<p>Disable Options:</p> <p>Disable Options:</p>
<div className="slider"> <div className="slider">
<div {/* Offline */}
className={`slider-option ${selectedOption === 'Offline' ? 'active' : ''} ${openSourceMode ? 'disabled' : ''}`} <div
onClick={() => !openSourceMode && handleRadioChange('Offline')} // Handle selection only if not in open source mode className={`slider-option ${selectedOption === 'Offline' ? 'active' : ''}`}
> onClick={() => handleRadioChange('Offline')} // Allow selection only if not in open-source mode
Offline tools >
</div> Offline tools{openSourceMode ? ' (FOSS)' : ''}
<div </div>
className={`slider-option ${selectedOption === 'AI Online' ? 'active' : ''} ${openSourceMode ? 'disabled' : ''}`}
onClick={() => !openSourceMode && handleRadioChange('AI Online')} {/* Online */}
> <div
Online tools className={`slider-option ${selectedOption === 'Online' ? 'active' : ''}`}
</div> onClick={() => handleRadioChange('Online')}
<div >
className={`slider-option ${selectedOption === 'None' ? 'active' : ''} ${openSourceMode ? 'disabled' : ''}`} Online tools{openSourceMode ? ' (FOSS)' : ''}
onClick={() => !openSourceMode && handleRadioChange('None')} </div>
>
None {/* None */}
</div> <div
</div> className={`slider-option ${selectedOption === 'None' ? 'active' : ''}`}
<br /> onClick={() => handleRadioChange('None')}
{openSourceMode && ( >
<p style={{ color: 'grey' }}>These options are deactivated because you are in FOSS mode.</p> None{openSourceMode ? ' (FOSS)' : ''}
)} </div>
<p> </div>
After changing the preferred settings, please reload the website so it can update itself properly. <br />
</p> <p>
</div> After changing the preferred settings, please reload the website so it can update itself properly.
</p>
</div>
{/* Disable Chat History Checkbox */} {/* Disable Chat History Checkbox */}
<div className="settings-option"> <div className="settings-option">
@ -814,10 +820,8 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
// Update radio selection based on the new openSourceMode value // Update radio selection based on the new openSourceMode value
if (newValue) { if (newValue) {
setSelectedOption('FOSS'); // Set to FOSS if enabling open source mode setSelectedOption('FOSS'); // Set to FOSS if enabling open source mode
localStorage.setItem('radioSelection', 'FOSS'); // Update localStorage
} else { } else {
setSelectedOption('None'); // Or any other default value when disabling setSelectedOption('None'); // Or any other default value when disabling
localStorage.setItem('radioSelection', 'None'); // Update localStorage
} }
}} }}
/> />
@ -995,6 +999,13 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
<h2>Settings for {accountName}</h2> <h2>Settings for {accountName}</h2>
{renderSettingsContent()} {renderSettingsContent()}
<button className="close-popup" onClick={closeSettings}>Close</button> <button className="close-popup" onClick={closeSettings}>Close</button>
<button className="apply" onClick={() => {
applySettings;
getAllLocalStorageItems();
closeSettings(); // This is invoked when the button is clicked
}}>
Apply
</button>
</div> </div>
</div> </div>
</div> </div>

View file

@ -109,6 +109,20 @@
transition: background 0.3s; transition: background 0.3s;
} }
/* Close button positioning */
.apply {
background: var(--close-button-color); /* Use variable for close button color */
color: white; /* Use white for text color */
border: none;
border-radius: 5px;
padding: 5px 10px;
cursor: pointer;
position: absolute; /* Position the button absolutely */
top: 50px; /* Distance from the top */
right: 10px; /* Distance from the right */
transition: background 0.3s;
}
.close-popup:hover { .close-popup:hover {
background: darkred; /* Optional hover effect */ background: darkred; /* Optional hover effect */
} }