persist models in localStorage, minor changes

This commit is contained in:
Daniel Avila 2023-02-22 21:30:48 -05:00
parent e2a3ecbf88
commit 1a6cddb8bb
6 changed files with 27 additions and 14 deletions

View file

@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { setModel } from '~/store/submitSlice';
import GPTIcon from '../svg/GPTIcon';
@ -22,6 +22,18 @@ export default function ModelMenu() {
dispatch(setModel(value));
};
useEffect(() => {
const lastSelectedModel = JSON.parse(localStorage.getItem('model'));
if (lastSelectedModel) {
dispatch(setModel(lastSelectedModel));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => {
localStorage.setItem('model', JSON.stringify(model));
}, [model]);
const defaultColorProps = [
'text-gray-500',
'hover:bg-gray-100',