From 03aabd26742d19b2de0cf44be417dc466080ab91 Mon Sep 17 00:00:00 2001 From: sageTheDM Date: Tue, 1 Oct 2024 16:53:59 +0200 Subject: [PATCH] Gave the models a visual feedback what is active --- app/components/Models.tsx | 47 +++++++++++++++++++++++++++++++-------- app/styles/models.css | 5 +++++ 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/app/components/Models.tsx b/app/components/Models.tsx index 525b569..dee935e 100644 --- a/app/components/Models.tsx +++ b/app/components/Models.tsx @@ -153,26 +153,50 @@ const modelDropdown = { onlineFoss: ['Online (FOSS) (La Plateforme)'], }; +const Category = [ + 'Code', + 'Math', + 'Language', + 'Character', + 'Finance', + 'Weather', + 'Time', + 'Image', + 'Custom1', + 'Custom2' +] + const Models: React.FC = () => { // Initialize state with value from localStorage or default to '' const [selectedModel, setSelectedModel] = useState(''); const [radioSelection, setRadioSelection] = useState("") + const [activeCategory, setActiveCategory] = useState(''); + const [currentCategory, setCurrentCategory] = useState(localStorage.getItem("activeCategory")); useEffect(() => { - setRadioSelection(localStorage.getItem('radioSelection')) + // Retrieve initial values from localStorage + setRadioSelection(localStorage.getItem('radioSelection') || ''); + setSelectedModel(localStorage.getItem('selectedModel') || ''); + const handleStorageChange = () => { setSelectedModel(localStorage.getItem('selectedModel') || ''); }; - handleStorageChange(); - // Update dropdown immediately when localStorage changes internally or externally + // Update immediately when localStorage changes window.addEventListener('storage', handleStorageChange); // Cleanup listener on component unmount return () => { window.removeEventListener('storage', handleStorageChange); }; - }, []); + }, []); // 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); + } + }, [activeCategory]); const handleModelChange = (event: React.ChangeEvent) => { const newModel = event.target.value; @@ -236,6 +260,8 @@ const Models: React.FC = () => { modelDropdown.offlineWithoutFoss.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]]) @@ -260,14 +286,17 @@ const Models: React.FC = () => { - {/* Model Grid with Cards */}
- {['Code', 'Math', 'Language', 'Character', 'Finance', 'Weather', 'Time', 'Image', 'Custom1', 'Custom2'].map( - (category) => ( - diff --git a/app/styles/models.css b/app/styles/models.css index cb00319..ccd49c6 100644 --- a/app/styles/models.css +++ b/app/styles/models.css @@ -60,6 +60,11 @@ margin: auto; /* Center each model box in the grid cell */ } +.model-box.selected { + box-shadow: 0 0 15px 5px rgba(255, 255, 0, 0.7); /* Glowing border */ + border-color: yellow; +} + .overlay { position: absolute; left: 0;