From fc6fa36c15a0d57cb6180d81d315ca54883b3e2a Mon Sep 17 00:00:00 2001 From: alewin Date: Fri, 7 Apr 2023 00:17:35 +0800 Subject: [PATCH] sidebar menu --- src/components/PromptBook.tsx | 2 +- src/components/Settings.tsx | 4 +- src/components/Sidebar.tsx | 66 ++++++++++++ src/containers/StartView.tsx | 49 +-------- src/pages/index.tsx | 185 ++++++++++++++++++---------------- 5 files changed, 168 insertions(+), 138 deletions(-) create mode 100644 src/components/Sidebar.tsx diff --git a/src/components/PromptBook.tsx b/src/components/PromptBook.tsx index 25a695d..0d3e694 100644 --- a/src/components/PromptBook.tsx +++ b/src/components/PromptBook.tsx @@ -36,7 +36,7 @@ export function PromptBook() { return (
)} > +} +export const Sidebar: React.FC = ({ setMenu }) => { + const MenusData = [QuickStartMenu, ChatViewMenu, ConfigMenu, ModelsMenu, PromptsMenu] + MenusData.forEach((menu, index) => { + menu.key = index + }) + + return ( +
    + {MenusData.map((item) => ( +
  • { + MenusData.forEach((m) => (m.state = "")) + MenusData[item.key].state = "active" + setMenu(item.key) + }} + > + {item.name} +
  • + ))} + +
+ ) +} diff --git a/src/containers/StartView.tsx b/src/containers/StartView.tsx index a7a4b67..3134148 100644 --- a/src/containers/StartView.tsx +++ b/src/containers/StartView.tsx @@ -5,26 +5,18 @@ import { open } from "@/lib/dialog" import { StoreType } from "@/lib/store" interface StartViewProps { store: StoreType - running: boolean output: string downloading: boolean downloadingFile: string downloadProgress: number - onSelectDirClick: () => void - onStartClick: () => void - onInitClick: () => void } export const StartView: React.FC = ({ store, - running, output, downloading, downloadingFile, downloadProgress, - onSelectDirClick, - onInitClick, - onStartClick, }: StartViewProps) => { const goToPythonDownload = () => { void openLink("https://www.python.org/downloads/") @@ -120,47 +112,8 @@ export const StartView: React.FC = ({ )}
-
-
- - {running ? ( - <> - - - - ) : ( - <> - - - - )} -
-
-
+

Output:

{downloading && ( diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 124a019..0ebd31a 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -7,54 +7,28 @@ import Head from "next/head" import { useEffect, useState } from "react" import { themeChange } from "theme-change" +import { + ChatViewMenu, + ConfigMenu, + ModelsMenu, + PromptsMenu, + QuickStartMenu, + Sidebar, +} from "@/components/Sidebar" import ChatView from "@/containers/ChatView" import { ConfigView } from "@/containers/ConfigView" import { StartView } from "@/containers/StartView" import { useGlobalShortcut } from "@/hooks/tauri/shortcuts" -import { listen, openWebview, resolveResource } from "@/lib/api" +import { listen, openWebview } from "@/lib/api" import { open } from "@/lib/dialog" import useStore from "@/lib/store" const regex = /(https?:\/\/[^ ]*)/ -const QuickStartMenu = { - key: 0, - name: "Quick Start", - state: "active", - desc: "One Click to start", -} -const ChatViewMenu = { - key: 1, - name: "Chat", - state: "", - desc: "Chat with the sd", -} -const ConfigMenu = { - key: 2, - name: "Configuration", - state: "", - desc: "A lot of configurations", -} -const ModelsMenu = { - key: 3, - name: "Models", - state: "", - desc: "Model files", -} -const PromptsMenu = { - key: 4, - name: "Prompts", - state: "", - desc: "Prompt collections", -} const Home: NextPage = () => { - const MenusData = [QuickStartMenu, ChatViewMenu, ConfigMenu, ModelsMenu, PromptsMenu] - MenusData.forEach((menu, index) => { - menu.key = index - }) const store = useStore() - const [menu, setMenu] = useState(QuickStartMenu.key) + const [menu, setMenu] = useState(0) const [running, setRunning] = useState(false) const [shellOutput, setShellOutput] = useState("") @@ -177,62 +151,99 @@ const Home: NextPage = () => { }) return ( -
+
SD Desk -
    - {MenusData.map((item) => ( -
  • { - MenusData.forEach((m) => (m.state = "")) - MenusData[item.key].state = "active" - setMenu(item.key) - }} - > - {item.name} -
  • - ))} - -
- -
- {menu === ConfigMenu.key && } - {menu === QuickStartMenu.key && ( - - )} - {menu === ChatViewMenu.key && } - {menu === ModelsMenu.key && ( - - )} - {menu === PromptsMenu.key && ( - - )} -
+ +
+
+
+ +
+
+ + {running ? ( + <> + + + + ) : ( + <> + + + + )} +
+
+
+ {menu === ConfigMenu.key && } + {menu === QuickStartMenu.key && ( + + )} + {menu === ChatViewMenu.key && } + {menu === ModelsMenu.key && ( + + )} + {menu === PromptsMenu.key && ( + + )} +
+
+
+ + +
+ {errorInfo && (