From d55a83888b1fcaa987184ec98460c56194fc84b4 Mon Sep 17 00:00:00 2001 From: NamH Date: Wed, 13 Sep 2023 21:33:53 -0700 Subject: [PATCH] refactor: replacing mobx with jotai (#160) * refactor: replacing mobx with jotai Signed-off-by: James Co-authored-by: James Co-authored-by: Louis --- conf/sample.env_web-client | 3 +- web-client/README.md | 4 +- .../app/_components/AdvancedPrompt/index.tsx | 98 +- .../_components/AdvancedTextArea/index.tsx | 54 +- web-client/app/_components/ApiPane/index.tsx | 156 +- web-client/app/_components/ApiStep/index.tsx | 30 +- .../BasicPromptAccessories/index.tsx | 40 + .../_components/BasicPromptButton/index.tsx | 20 + .../_components/BasicPromptInput/index.tsx | 38 + .../app/_components/ButtonSlider/index.tsx | 84 +- .../app/_components/ChangeTheme/index.tsx | 50 +- web-client/app/_components/ChatBody/index.tsx | 215 +- .../ChatBody/renderChatMessage.tsx | 66 + .../app/_components/ChatContainer/index.tsx | 103 +- web-client/app/_components/ChatItem/index.tsx | 19 + .../_components/CompactHistoryItem/index.tsx | 30 +- .../_components/CompactHistoryList/index.tsx | 21 + .../app/_components/CompactLogo/index.tsx | 10 +- .../app/_components/CompactSideBar/index.tsx | 38 +- .../ConfirmDeleteConversationModal/index.tsx | 29 +- .../_components/ConfirmSignOutModal/index.tsx | 21 +- .../_components/ConversationalCard/index.tsx | 10 +- .../_components/ConversationalList/index.tsx | 12 +- .../app/_components/Draggable/index.tsx | 37 - .../app/_components/DropdownList/index.tsx | 128 +- .../_components/ExpandableHeader/index.tsx | 24 + .../_components/GenerateImageCard/index.tsx | 18 +- .../_components/GenerateImageList/index.tsx | 42 +- .../GenerativeSampleContainer/index.tsx | 101 +- .../app/_components/HamburgerButton/index.tsx | 22 + web-client/app/_components/Header/index.tsx | 77 +- .../app/_components/HistoryEmpty/index.tsx | 54 +- .../app/_components/HistoryItem/index.tsx | 144 +- .../app/_components/HistoryList/index.tsx | 99 +- .../app/_components/InputToolbar/index.tsx | 153 +- web-client/app/_components/JanLogo/index.tsx | 19 + .../app/_components/JanWelcomeTitle/index.tsx | 40 +- .../app/_components/LeftContainer/index.tsx | 24 + .../app/_components/LeftSidebar/index.tsx | 20 + .../app/_components/LoginButton/index.tsx | 27 + web-client/app/_components/MainChat/index.tsx | 13 + .../app/_components/MainChatHeader/index.tsx | 11 + .../_components/MenuAdvancedPrompt/index.tsx | 44 +- .../app/_components/MenuHeader/index.tsx | 111 +- .../app/_components/MobileDownload/index.tsx | 4 +- .../app/_components/MobileMenuPane/index.tsx | 94 +- .../_components/ModelDetailSideBar/index.tsx | 45 +- .../app/_components/ModelInfo/index.tsx | 84 +- .../app/_components/ModelInfoItem/index.tsx | 30 +- .../app/_components/ModelMenu/index.tsx | 90 +- .../_components/NewChatBlankState/index.tsx | 54 - web-client/app/_components/OverviewPane.tsx | 120 +- .../app/_components/PrimaryButton/index.tsx | 25 + .../app/_components/ProductOverview/index.tsx | 29 + .../app/_components/RightContainer/index.tsx | 14 + .../_components/SampleLlmContainer/index.tsx | 90 +- .../app/_components/SearchBar/index.tsx | 54 +- .../app/_components/SecondaryButton/index.tsx | 18 + .../app/_components/SendButton/index.tsx | 20 +- .../app/_components/ShortcutItem/index.tsx | 24 +- .../app/_components/ShortcutList/index.tsx | 74 +- .../app/_components/SidebarLeft/index.tsx | 109 - .../_components/SimpleImageMessage/index.tsx | 177 +- .../_components/SimpleTextMessage/index.tsx | 112 +- web-client/app/_components/Slide/index.tsx | 13 +- web-client/app/_components/Slider/index.tsx | 12 +- .../_components/StreamTextMessage/index.tsx | 102 +- .../app/_components/TabModelDetail/index.tsx | 70 +- web-client/app/_components/TextCode/index.tsx | 62 +- .../app/_components/TitleBlankState/index.tsx | 22 +- .../app/_components/TryItYourself/index.tsx | 39 + .../app/_components/UploadFileImage/index.tsx | 204 +- .../_components/UserProfileDropDown/index.tsx | 10 +- .../app/_components/UserToolbar/index.tsx | 52 +- web-client/app/_helpers/JotaiWrapper.tsx | 215 + web-client/app/_helpers/MobxWrapper.tsx | 13 - web-client/app/_helpers/ModalWrapper.tsx | 19 + web-client/app/_helpers/ThemeWrapper.tsx | 13 +- web-client/app/_helpers/withSetPropAction.ts | 30 - .../app/_hooks/useChatMessageSubscription.ts | 16 + web-client/app/_hooks/useChatMessages.ts | 73 + .../app/_hooks/useCreateConversation.ts | 56 +- .../app/_hooks/useDeleteConversation.ts | 50 + web-client/app/_hooks/useGetCurrentUser.ts | 6 +- web-client/app/_hooks/useGetProducts.ts | 24 + .../app/_hooks/useGetUserConversations.ts | 56 +- web-client/app/_hooks/useSendChatMessage.ts | 383 ++ web-client/app/_hooks/useSignOut.ts | 13 +- web-client/app/_models/ChatMessage.ts | 70 +- web-client/app/_models/Conversation.ts | 116 +- web-client/app/_models/History.ts | 604 --- web-client/app/_models/Input.ts | 19 - web-client/app/_models/Output.ts | 14 - web-client/app/_models/Product.ts | 90 +- web-client/app/_models/ProductInput.ts | 23 + web-client/app/_models/ProductOutput.ts | 8 + web-client/app/_models/ProductV2.ts | 81 - web-client/app/_models/RootStore.ts | 36 - web-client/app/_models/Shortcut.ts | 7 - web-client/app/_models/User.ts | 21 +- web-client/app/_utils/const.ts | 2 +- web-client/app/_utils/message.ts | 9 +- web-client/app/layout.tsx | 24 +- web-client/app/page.tsx | 45 +- web-client/env-example | 3 +- web-client/graphql/fragments/product.graphql | 2 + web-client/graphql/generated/gql.ts | 16 +- web-client/graphql/generated/graphql.ts | 42 +- .../queries/getConversationMessages.graphql | 2 +- .../graphql/queries/getConversations.graphql | 2 +- .../subscriptions/subscribeMessage.graphql | 1 + web-client/package-lock.json | 4369 ----------------- web-client/package.json | 10 +- web-client/tailwind.config.js | 3 + web-client/yarn.lock | 679 ++- 115 files changed, 3755 insertions(+), 7722 deletions(-) create mode 100644 web-client/app/_components/BasicPromptAccessories/index.tsx create mode 100644 web-client/app/_components/BasicPromptButton/index.tsx create mode 100644 web-client/app/_components/BasicPromptInput/index.tsx create mode 100644 web-client/app/_components/ChatBody/renderChatMessage.tsx create mode 100644 web-client/app/_components/ChatItem/index.tsx create mode 100644 web-client/app/_components/CompactHistoryList/index.tsx delete mode 100644 web-client/app/_components/Draggable/index.tsx create mode 100644 web-client/app/_components/ExpandableHeader/index.tsx create mode 100644 web-client/app/_components/HamburgerButton/index.tsx create mode 100644 web-client/app/_components/JanLogo/index.tsx create mode 100644 web-client/app/_components/LeftContainer/index.tsx create mode 100644 web-client/app/_components/LeftSidebar/index.tsx create mode 100644 web-client/app/_components/LoginButton/index.tsx create mode 100644 web-client/app/_components/MainChat/index.tsx create mode 100644 web-client/app/_components/MainChatHeader/index.tsx delete mode 100644 web-client/app/_components/NewChatBlankState/index.tsx create mode 100644 web-client/app/_components/PrimaryButton/index.tsx create mode 100644 web-client/app/_components/ProductOverview/index.tsx create mode 100644 web-client/app/_components/RightContainer/index.tsx create mode 100644 web-client/app/_components/SecondaryButton/index.tsx delete mode 100644 web-client/app/_components/SidebarLeft/index.tsx create mode 100644 web-client/app/_components/TryItYourself/index.tsx create mode 100644 web-client/app/_helpers/JotaiWrapper.tsx delete mode 100644 web-client/app/_helpers/MobxWrapper.tsx create mode 100644 web-client/app/_helpers/ModalWrapper.tsx delete mode 100644 web-client/app/_helpers/withSetPropAction.ts create mode 100644 web-client/app/_hooks/useChatMessageSubscription.ts create mode 100644 web-client/app/_hooks/useChatMessages.ts create mode 100644 web-client/app/_hooks/useDeleteConversation.ts create mode 100644 web-client/app/_hooks/useGetProducts.ts create mode 100644 web-client/app/_hooks/useSendChatMessage.ts delete mode 100644 web-client/app/_models/History.ts delete mode 100644 web-client/app/_models/Input.ts delete mode 100644 web-client/app/_models/Output.ts create mode 100644 web-client/app/_models/ProductInput.ts create mode 100644 web-client/app/_models/ProductOutput.ts delete mode 100644 web-client/app/_models/ProductV2.ts delete mode 100644 web-client/app/_models/RootStore.ts delete mode 100644 web-client/app/_models/Shortcut.ts delete mode 100644 web-client/package-lock.json diff --git a/conf/sample.env_web-client b/conf/sample.env_web-client index 35fc6972c0..e024bb7623 100644 --- a/conf/sample.env_web-client +++ b/conf/sample.env_web-client @@ -5,8 +5,7 @@ NEXT_PUBLIC_DOWNLOAD_APP_IOS=# NEXT_PUBLIC_DOWNLOAD_APP_ANDROID=# NEXT_PUBLIC_GRAPHQL_ENGINE_URL=http://localhost:8080/v1/graphql NEXT_PUBLIC_GRAPHQL_ENGINE_WEB_SOCKET_URL=ws://localhost:8080/v1/graphql -OPENAPI_ENDPOINT=http://host.docker.internal:8000/v1 -OPENAPI_KEY=openapikey +NEXT_PUBLIC_OPENAPI_ENDPOINT=http://localhost:8000/v1/chat/completions KEYCLOAK_CLIENT_ID=hasura KEYCLOAK_CLIENT_SECRET=oMtCPAV7diKpE564SBspgKj4HqlKM4Hy AUTH_ISSUER=http://localhost:8088/realms/$KEYCLOAK_CLIENT_ID diff --git a/web-client/README.md b/web-client/README.md index a356757177..ef0d70d5e1 100644 --- a/web-client/README.md +++ b/web-client/README.md @@ -77,9 +77,7 @@ Replace above configuration with your actual infrastructure. | [@tailwindcss/typography](https://tailwindcss.com/docs/typography-plugin) | UI | ^0.5.9 | | [embla-carousel](https://www.embla-carousel.com/) | UI | ^8.0.0-rc11 | | [@apollo/client](https://www.apollographql.com/docs/react/) | State management | ^3.8.1 | -| [mobx](https://mobx.js.org/README.html) | State management | ^6.10.0 | -| [mobx-react-lite](https://www.npmjs.com/package/mobx-react-lite) | State management | ^4.0.3 | -| [mobx-state-tree](https://mobx-state-tree.js.org/) | State management | ^5.1.8 | +| [jotai](https://jotai.org/) | State management | ^2.4.0 | ## Deploy to Netlify diff --git a/web-client/app/_components/AdvancedPrompt/index.tsx b/web-client/app/_components/AdvancedPrompt/index.tsx index 19270ef3f8..168e784db7 100644 --- a/web-client/app/_components/AdvancedPrompt/index.tsx +++ b/web-client/app/_components/AdvancedPrompt/index.tsx @@ -1,69 +1,29 @@ -"use client"; -import { useCallback } from "react"; -import Image from "next/image"; -import { useStore } from "@/_models/RootStore"; -import { observer } from "mobx-react-lite"; -import { MenuAdvancedPrompt } from "../MenuAdvancedPrompt"; -import { useForm } from "react-hook-form"; -import { useMutation } from "@apollo/client"; -import { CreateMessageDocument, CreateMessageMutation } from "@/graphql"; - -export const AdvancedPrompt: React.FC = observer(() => { - const { register, handleSubmit } = useForm(); - const { historyStore } = useStore(); - - const onAdvancedPrompt = useCallback(() => { - historyStore.toggleAdvancedPrompt(); - }, []); - - const [createMessageMutation] = useMutation( - CreateMessageDocument - ); - const onSubmit = (data: any) => { - historyStore.sendControlNetPrompt( - createMessageMutation, - data.prompt, - data.negativePrompt, - data.fileInput[0] - ); - }; - - return ( -
- -
- -
-
- - -
-
- ); -}); +import { MenuAdvancedPrompt } from "../MenuAdvancedPrompt"; +import { useForm } from "react-hook-form"; +import BasicPromptButton from "../BasicPromptButton"; +import PrimaryButton from "../PrimaryButton"; + +const AdvancedPrompt: React.FC = () => { + const { register, handleSubmit } = useForm(); + + const onSubmit = (data: any) => {}; + + return ( +
+ + +
+ handleSubmit(onSubmit)} + /> +
+ + ); +}; + +export default AdvancedPrompt; diff --git a/web-client/app/_components/AdvancedTextArea/index.tsx b/web-client/app/_components/AdvancedTextArea/index.tsx index 980efedaca..26be021a1e 100644 --- a/web-client/app/_components/AdvancedTextArea/index.tsx +++ b/web-client/app/_components/AdvancedTextArea/index.tsx @@ -1,27 +1,27 @@ -import { FieldValues, UseFormRegister } from "react-hook-form"; - -type Props = { - formId?: string; - height: number; - title: string; - placeholder: string; - register: UseFormRegister; -}; - -export const AdvancedTextArea: React.FC = ({ - formId = "", - height, - placeholder, - title, - register, -}) => ( -
- -