diff --git a/app/components/Login.tsx b/app/components/Login.tsx index b56d064..69b57d8 100644 --- a/app/components/Login.tsx +++ b/app/components/Login.tsx @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react'; import { createAccount, checkCredentials, + getData } from '../backend/database'; import Settings from './settings/Settings'; // Import the Settings component @@ -54,6 +55,10 @@ const Login: React.FC = () => { const success = await checkCredentials(accountName, password); if (success) { setIsLoggedIn(true); // Successful login + var data = await getData(accountName, password) + if (data) { + localStorage.setItem("dataFromServer", data) + } setShowLoginPopup(false); // Close the login popup } else { alert('Incorrect credentials'); diff --git a/app/components/Models.tsx b/app/components/Models.tsx index dee935e..6ca8aeb 100644 --- a/app/components/Models.tsx +++ b/app/components/Models.tsx @@ -137,11 +137,11 @@ const modelList = { } } -// Define the available category options +// Define the available selectedAIFunction options const modelDropdown = { - offlineWithoutFoss: ['Offline Fast', 'Offline Slow'], + offlineNonFoss: ['Offline Fast', 'Offline Slow'], offlineFoss: ['Offline Fast (FOSS)', 'Offline Slow (FOSS)'], - onlineWithoutFoss: [ + onlineNonFoss: [ 'Online Cheap (OpenAI)', 'Online Expensive (OpenAI)', 'Online Cheap (Anthropic)', @@ -153,7 +153,7 @@ const modelDropdown = { onlineFoss: ['Online (FOSS) (La Plateforme)'], }; -const Category = [ +const selectedAIFunction = [ 'Code', 'Math', 'Language', @@ -166,25 +166,38 @@ const Category = [ 'Custom2' ] -const Models: React.FC = () => { +const ModelSection: React.FC = () => { // Initialize state with value from localStorage or default to '' - const [selectedModel, setSelectedModel] = useState(''); + const [selectedModelDropdown, setSelectedModelDropdown] = useState(''); const [radioSelection, setRadioSelection] = useState("") - const [activeCategory, setActiveCategory] = useState(''); - const [currentCategory, setCurrentCategory] = useState(localStorage.getItem("activeCategory")); - + const [activeSelectedAIFunction, setActiveSelectedAIFunction] = useState(''); + const [currentSelectedAIFunction, setCurrentSelectedAIFunction] = useState(""); + useEffect(() => { - // Retrieve initial values from localStorage - setRadioSelection(localStorage.getItem('radioSelection') || ''); - setSelectedModel(localStorage.getItem('selectedModel') || ''); + var temp = localStorage.getItem("activeSelectedAIFunction") || "" + setActiveSelectedAIFunction(temp) + if (!localStorage.getItem('selectedModelDropdown')) { + localStorage.setItem("selectedModelDropdown", "Offline Fast" ) + } + + if (!localStorage.getItem("activeSelectedAIFunction")) { + setActiveSelectedAIFunction('Code') + localStorage.setItem('activeSelectedAIFunction' ,'Code') + } + + if (!localStorage.getItem("model")) { + localStorage.setItem("model" ,'starcoder2') + } const handleStorageChange = () => { - setSelectedModel(localStorage.getItem('selectedModel') || ''); + setSelectedModelDropdown(localStorage.getItem('selectedModelDropdown') || ''); }; // Update immediately when localStorage changes window.addEventListener('storage', handleStorageChange); + setRadioSelection(localStorage.getItem('radioSelection') || ''); + setSelectedModelDropdown(localStorage.getItem('selectedModelDropdown') || ''); // Cleanup listener on component unmount return () => { window.removeEventListener('storage', handleStorageChange); @@ -192,16 +205,16 @@ const Models: React.FC = () => { }, []); // Dependency array can remain empty if you only want this to run on mount useEffect(() => { - const storedCategory = localStorage.getItem("activeCategory"); - if (storedCategory !== currentCategory) { - setCurrentCategory(storedCategory); + var storedActiveSelectedAIFunction = localStorage.getItem("activeSelectedAIFunction") || ""; + if (storedActiveSelectedAIFunction !== currentSelectedAIFunction) { + setCurrentSelectedAIFunction(storedActiveSelectedAIFunction); } - }, [activeCategory]); + }, [activeSelectedAIFunction]); const handleModelChange = (event: React.ChangeEvent) => { const newModel = event.target.value; - setSelectedModel(newModel); - localStorage.setItem('selectedModel', newModel); // Update localStorage directly + setSelectedModelDropdown(newModel); + localStorage.setItem('selectedModelDropdown', newModel); // Update localStorage directly }; // Determine the filtered models based on current radioSelection @@ -210,7 +223,7 @@ const Models: React.FC = () => { switch (radioSelection) { case 'Offline': models = [ - ...modelDropdown.onlineWithoutFoss, + ...modelDropdown.onlineNonFoss, ...modelDropdown.onlineFoss, ]; // Show only offline models without FOSS break; @@ -221,7 +234,7 @@ const Models: React.FC = () => { break; case 'Online': models = [ - ...modelDropdown.offlineWithoutFoss, + ...modelDropdown.offlineNonFoss, ...modelDropdown.offlineFoss, ]; // Show only online models without FOSS break; @@ -232,9 +245,9 @@ const Models: React.FC = () => { break; case 'None': models = [ - ...modelDropdown.offlineWithoutFoss, + ...modelDropdown.offlineNonFoss, ...modelDropdown.offlineFoss, - ...modelDropdown.onlineWithoutFoss, + ...modelDropdown.onlineNonFoss, ...modelDropdown.onlineFoss, ]; // Show all models if nothing matches break; @@ -246,9 +259,9 @@ const Models: React.FC = () => { break; default: models = [ - ...modelDropdown.offlineWithoutFoss, + ...modelDropdown.offlineNonFoss, ...modelDropdown.offlineFoss, - ...modelDropdown.onlineWithoutFoss, + ...modelDropdown.onlineNonFoss, ...modelDropdown.onlineFoss, ]; // Show all models if nothing matches break; @@ -257,14 +270,14 @@ const Models: React.FC = () => { })(); const isOfflineModel = (model: string) => - modelDropdown.offlineWithoutFoss.includes(model) || modelDropdown.offlineFoss.includes(model); + modelDropdown.offlineNonFoss.includes(model) || modelDropdown.offlineFoss.includes(model); const modelClicked = (model: string) => { - localStorage.setItem('activeCategory' , model) - setActiveCategory(model) - const category = selectedModel as keyof typeof modelList; - localStorage.setItem("model", modelList[category][model as keyof typeof modelList[typeof category]]) - localStorage.setItem("type", modelList[category]['model_type' as keyof typeof modelList[typeof category]]) + localStorage.setItem('activeSelectedAIFunction' , model) + setActiveSelectedAIFunction(model) + const selectedAIFunction = selectedModelDropdown as keyof typeof modelList; + localStorage.setItem("model", modelList[selectedAIFunction][model as keyof typeof modelList[typeof selectedAIFunction]]) + localStorage.setItem("type", modelList[selectedAIFunction]['model_type' as keyof typeof modelList[typeof selectedAIFunction]]) } return ( @@ -277,7 +290,7 @@ const Models: React.FC = () => { {/* Model Selection Dropdown */}
- {filteredModels.map((model) => (