From e6e5913cd68a6b7ebcf44316a2fcb1bd6f7bac18 Mon Sep 17 00:00:00 2001 From: crazywoola <427733928@qq.com> Date: Wed, 5 Jul 2023 09:39:58 +0800 Subject: [PATCH] feat: use state --- app/chat/main.tsx | 72 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/app/chat/main.tsx b/app/chat/main.tsx index 8895f98..914c2df 100644 --- a/app/chat/main.tsx +++ b/app/chat/main.tsx @@ -9,11 +9,21 @@ import Form from '@/components/form' import XPowerBy, { XPowerByPrivacy } from '@/components/x-power-by' import I18N from '@/i18n' +enum Status { + INIT = 'init', + READY = 'ready', + TYPING = 'typing', + SENDING = 'sending', + ERROR = 'error', + SUCCESS = 'success' +} + interface ExtraPropss { user: string conversations: ConversationsProps[] } interface IState { + status: Status conversations: ConversationsProps[] inputs: any query: string @@ -28,6 +38,8 @@ interface IAction { function reducer(state: IState, action: IAction): IState { switch (action.type) { + case 'NEW_CONVERSATION': + return action.payload case 'SET_QUERY': return { ...state, @@ -40,6 +52,7 @@ function reducer(state: IState, action: IAction): IState { }) return { ...state, + status: Status.READY, inputs: h } case 'SET_CONVERSATION_ID': @@ -52,6 +65,9 @@ function reducer(state: IState, action: IAction): IState { } } } +const Chat: FC = ({}) => { + return <>Chat +} const Main: FC = ({ user, @@ -60,6 +76,7 @@ const Main: FC = ({ conversations }) => { const initialState: IState = { + status: Status.INIT, conversations, inputs: [], query: '', @@ -83,6 +100,7 @@ const Main: FC = ({ options: iv.options } }) + return ( <>
@@ -98,7 +116,9 @@ const Main: FC = ({
-
- -
-
-
{ - dispatch({ - type: 'SET_INPUT', - payload: items - }) - }} - /> -
+ {state.status == Status.INIT ? ( + <> +
+ +
+
+ { + dispatch({ + type: 'SET_INPUT', + payload: items + }) + }} + /> +
-
- - -
+
+ + +
+ + ) : ( + + )}
)