优化体验: 缓存表单数据

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'; import { WS_URL } from '@/config';
export const useFormStore = create(devtools((set, get) => ({ 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; export default useFormStore;

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

Loading…
Cancel
Save