优化体验: 缓存表单数据

dev/chat
Lei OT 2 years ago
parent da3a0037c7
commit d5f32690a4

@ -7,7 +7,10 @@ import { devtools } from 'zustand/middleware';
import { WS_URL } from '@/config';
export const useFormStore = create(devtools((set, get) => ({
chatHistory: {},
setChatHistory: (chatHistory) => set({ chatHistory }),
// 历史记录页面
chatHistoryForm: {},
setChatHistoryForm: (chatHistoryForm) => set({ chatHistoryForm, chatHistorySelectChat: {} }),
chatHistorySelectChat: {},
setChatHistorySelectChat: (chatHistorySelectChat) => set({ chatHistorySelectChat }),
})));
export default useFormStore;

@ -188,10 +188,8 @@ const SearchForm = memo(function ({ initialValues, onSubmit }) {
function ChatHistory() {
// const [formValues, setFormValues] = useState({});
const [formValues, setFormValues] = useFormStore(
useShallow((state) => [state.chatHistory, state.setChatHistory]),
)
const [formValues, setFormValues] = useFormStore(useShallow((state) => [state.chatHistoryForm, state.setChatHistoryForm]));
const [selectedConversation, setSelectedConversation] = useFormStore(useShallow((state) => [state.chatHistorySelectChat, state.setChatHistorySelectChat]));
const handleSubmit = useCallback((values) => {
setFormValues({ ...values });
@ -199,7 +197,6 @@ function ChatHistory() {
const [loading, setLoading] = useState(false);
const [conversationsList, setConversationsList] = useState([]);
const [selectedConversation, setSelectedConversation] = useState({});
const [chatItemMessages, setChatItemMessages] = useState([]);
const getConversationsList = async () => {
setLoading(true);

Loading…
Cancel
Save