refactor: bing button

THIS IS NOT FINISHED. DONT USE THIS
This commit is contained in:
Wentao Lyu 2023-03-28 23:00:29 +08:00
parent c7c30d8bb5
commit 8ea98cca5d
5 changed files with 32 additions and 278 deletions

View file

@ -1,36 +1,38 @@
import React, { useState, useEffect, forwardRef } from 'react';
import { Tabs, TabsList, TabsTrigger } from '../ui/Tabs.tsx';
import { useDispatch, useSelector } from 'react-redux';
import { setConversation } from '~/store/convoSlice';
import { useRecoilValue, useRecoilState } from 'recoil';
// import { setConversation } from '~/store/convoSlice';
import store from '~/store';
function BingStyles(props, ref) {
const dispatch = useDispatch();
const [value, setValue] = useState('fast');
const { model } = useSelector((state) => state.submit);
const { conversationId } = useSelector((state) => state.convo);
const { messages } = useSelector((state) => state.messages);
const [conversation, setConversation] = useRecoilState(store.conversation) || {};
const { model, conversationId } = conversation;
const messages = useRecoilValue(store.messages);
const isBing = model === 'bingai' || model === 'sydney';
useEffect(() => {
if (model === 'bingai' && !conversationId || model === 'sydney') {
dispatch(setConversation({ toneStyle: value }));
if ((model === 'bingai' && !conversationId) || model === 'sydney') {
setConversation(prevState => ({ ...prevState, toneStyle: value }));
}
}, [conversationId, model, value, dispatch]);
}, [conversationId, model, value]);
const show = isBing && ((!conversationId || messages?.length === 0) || props.show);
const show = isBing && (!conversationId || messages?.length === 0 || props.show);
const defaultClasses = 'p-2 rounded-md font-normal bg-white/[.60] dark:bg-gray-700 text-black';
const defaultSelected = defaultClasses + 'font-medium data-[state=active]:text-white';
const selectedClass = (val) => val + '-tab ' + defaultSelected;
const selectedClass = val => val + '-tab ' + defaultSelected;
const changeHandler = value => {
setValue(value);
dispatch(setConversation({ toneStyle: value }));
setConversation(prevState => ({ ...prevState, toneStyle: value }));
};
return (
<Tabs
defaultValue={value}
className={`shadow-md mb-1 bing-styles ${show ? 'show' : ''}`}
className={`bing-styles mb-1 shadow-md ${show ? 'show' : ''}`}
onValueChange={changeHandler}
ref={ref}
>