Fixed the Models utilising useEffect #49

Merged
Patrick_Pluto merged 3 commits from sageTheDm/interstellar_ai:main into main 2024-09-25 13:38:46 +02:00

View file

@ -1,8 +1,6 @@
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
const Models: React.FC = () => { const Models: React.FC = () => {
const [selectedModel, setSelectedModel] = useState<string>('Offline Fast');
const modelOptions = [ const modelOptions = [
'Offline Fast', 'Offline Fast',
'Offline Fast (FOSS)', 'Offline Fast (FOSS)',
@ -18,14 +16,25 @@ const Models: React.FC = () => {
'Online Expensive (Google)', 'Online Expensive (Google)',
]; ];
const [selectedModel, setSelectedModel] = useState<string>(() => {
// Load the selected model from localStorage on initial render
return localStorage.getItem('selectedModel') || 'Offline Fast';
});
const handleModelChange = (event: React.ChangeEvent<HTMLSelectElement>) => { const handleModelChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
setSelectedModel(event.target.value); const newModel = event.target.value;
setSelectedModel(newModel);
}; };
const isOfflineModel = (model: string) => { const isOfflineModel = (model: string) => {
return model.includes('Offline'); return model.includes('Offline');
}; };
// Save selected model to localStorage whenever it changes
useEffect(() => {
localStorage.setItem('selectedModel', selectedModel);
}, [selectedModel]);
return ( return (
<div className="model-background"> <div className="model-background">
<div className="models"> <div className="models">