Merge pull request 'Fixed the Models utilising useEffect' (#49) from sageTheDm/interstellar_ai:main into main
Reviewed-on: https://interstellardevelopment.org/code/code/React-Group/interstellar_ai/pulls/49
This commit is contained in:
commit
0e6a096165
1 changed files with 13 additions and 4 deletions
|
@ -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">
|
||||||
|
|
Loading…
Reference in a new issue