From d6fdf410116752ea8d99567c3837794ebf144b3e Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Wed, 29 Mar 2023 11:25:27 -0400 Subject: [PATCH] fix: add text to global state --- client/src/components/Input/index.jsx | 4 ++-- client/src/components/ui/Landing.jsx | 5 +++-- client/src/store/index.js | 2 ++ client/src/store/text.js | 8 ++++++++ client/src/store/user.js | 15 ++++----------- 5 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 client/src/store/text.js diff --git a/client/src/components/Input/index.jsx b/client/src/components/Input/index.jsx index 9eac938c4c..9412093dec 100644 --- a/client/src/components/Input/index.jsx +++ b/client/src/components/Input/index.jsx @@ -6,7 +6,6 @@ import BingStyles from './BingStyles'; import ModelMenu from './Models/ModelMenu'; import Footer from './Footer'; import TextareaAutosize from 'react-textarea-autosize'; -import createPayload from '~/utils/createPayload'; import RegenerateIcon from '../svg/RegenerateIcon'; import StopGeneratingIcon from '../svg/StopGeneratingIcon'; import { useMessageHandler } from '../../utils/handleSubmit'; @@ -20,13 +19,14 @@ export default function TextChat({ isSearchView = false }) { const conversation = useRecoilValue(store.conversation); const latestMessage = useRecoilValue(store.latestMessage); const messages = useRecoilValue(store.messages); + const [text, setText] = useRecoilState(store.text); + // const [text, setText] = useState(''); const isSubmitting = useRecoilValue(store.isSubmitting); // TODO: do we need this? const disabled = false; - const [text, setText] = useState(''); const { ask, regenerate, stopGenerating } = useMessageHandler(); const bingStylesRef = useRef(null); diff --git a/client/src/components/ui/Landing.jsx b/client/src/components/ui/Landing.jsx index 9235973274..617e6903f1 100644 --- a/client/src/components/ui/Landing.jsx +++ b/client/src/components/ui/Landing.jsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { useRecoilValue } from 'recoil'; +import { useRecoilValue, useSetRecoilState } from 'recoil'; import useDocumentTitle from '~/hooks/useDocumentTitle'; import Templates from '../Prompts/Templates'; import SunIcon from '../svg/SunIcon'; @@ -11,6 +11,7 @@ import store from '~/store'; export default function Landing() { const [showingTemplates, setShowingTemplates] = useState(false); + const setText = useSetRecoilState(store.text); const conversation = useRecoilValue(store.conversation); const { title = 'New Chat' } = conversation || {}; @@ -20,7 +21,7 @@ export default function Landing() { e.preventDefault(); const { innerText } = e.target; const quote = innerText.split('"')[1].trim(); - // dispatch(setText(quote)); + setText(quote); }; const showTemplates = e => { diff --git a/client/src/store/index.js b/client/src/store/index.js index bce8c03bc7..ec169d4447 100644 --- a/client/src/store/index.js +++ b/client/src/store/index.js @@ -2,6 +2,7 @@ import conversation from './conversation'; import conversations from './conversations'; import models from './models'; import user from './user'; +import text from './text'; import submission from './submission'; import search from './search'; @@ -10,6 +11,7 @@ export default { ...conversations, ...models, ...user, + text, ...submission, ...search }; diff --git a/client/src/store/text.js b/client/src/store/text.js new file mode 100644 index 0000000000..d587d65af4 --- /dev/null +++ b/client/src/store/text.js @@ -0,0 +1,8 @@ +import { atom } from 'recoil'; + +const text = atom({ + key: 'text', + default: '' +}); + +export default text; diff --git a/client/src/store/user.js b/client/src/store/user.js index 24d9694982..060df1500b 100644 --- a/client/src/store/user.js +++ b/client/src/store/user.js @@ -1,17 +1,10 @@ -import React from "react"; -import { - RecoilRoot, - atom, - selector, - useRecoilState, - useRecoilValue, -} from "recoil"; +import { atom } from 'recoil'; const user = atom({ - key: "user", - default: null, + key: 'user', + default: null }); export default { - user, + user };