From e4543e1ba2429ca06d5572b38d887242d209ec15 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Wed, 6 Dec 2023 22:38:55 +0000 Subject: [PATCH] Add settings button to desktop --- desktop/src/configure.tsx | 23 +++++++++++++++------ desktop/src/main.tsx | 19 ++--------------- desktop/src/rqbit-desktop.tsx | 39 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 desktop/src/rqbit-desktop.tsx diff --git a/desktop/src/configure.tsx b/desktop/src/configure.tsx index 1641505..11616e6 100644 --- a/desktop/src/configure.tsx +++ b/desktop/src/configure.tsx @@ -53,10 +53,14 @@ const FormInput: React.FC<{ } export const ConfigModal: React.FC<{ - handleOk: (config: RqbitDesktopConfig) => void, + show: boolean, + handleStartReconfigure: () => void, + handleConfigured: (config: RqbitDesktopConfig) => void, + handleCancel?: () => void, initialConfig: RqbitDesktopConfig, -}> = ({ handleOk, initialConfig }) => { - const [config, setConfig] = useState(initialConfig); +}> = ({ show, handleStartReconfigure, handleConfigured, handleCancel, initialConfig }) => { + let [config, setConfig] = useState(initialConfig); + const [error, setError] = useState(null); const handleInputChange = (e: any) => { @@ -102,8 +106,9 @@ export const ConfigModal: React.FC<{ const handleOkClick = () => { setError(null); + handleStartReconfigure(); invokeAPI<{}>("config_change", { config }).then( - () => handleOk(config), + () => handleConfigured(config), (e: ErrorDetails) => { setError({ text: "Error saving configuration", @@ -114,14 +119,14 @@ export const ConfigModal: React.FC<{ }; return ( - + Configure Rqbit desktop @@ -282,6 +287,12 @@ export const ConfigModal: React.FC<{ + + {!!handleCancel && + + } diff --git a/desktop/src/main.tsx b/desktop/src/main.tsx index b74c247..1f7be92 100644 --- a/desktop/src/main.tsx +++ b/desktop/src/main.tsx @@ -4,7 +4,7 @@ import { APIContext, RqbitWebUI } from "./rqbit-webui-src/rqbit-web"; import { API } from "./api"; import { invoke } from "@tauri-apps/api"; import { RqbitDesktopConfig } from "./configuration"; -import { ConfigModal } from "./configure"; +import { RqbitDesktop } from "./rqbit-desktop"; async function get_version(): Promise { return invoke("get_version"); @@ -14,18 +14,6 @@ async function get_default_config(): Promise { return invoke("config_default"); } -const RqbitDesktop: React.FC<{ - version: string, - defaultConfig: RqbitDesktopConfig, -}> = ({ version, defaultConfig }) => { - let [configured, setConfigured] = useState(false); - - if (configured) { - return - } - return setConfigured(true)} initialConfig={defaultConfig}>; -} - Promise.all([get_version(), get_default_config()]).then(([version, config]) => { ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( @@ -34,7 +22,4 @@ Promise.all([get_version(), get_default_config()]).then(([version, config]) => { ); -}) - - - +}) \ No newline at end of file diff --git a/desktop/src/rqbit-desktop.tsx b/desktop/src/rqbit-desktop.tsx new file mode 100644 index 0000000..c739776 --- /dev/null +++ b/desktop/src/rqbit-desktop.tsx @@ -0,0 +1,39 @@ +import { useState } from "react"; +import { RqbitWebUI } from "./rqbit-webui-src/rqbit-web"; +import { RqbitDesktopConfig } from "./configuration"; +import { ConfigModal } from "./configure"; + + +export const RqbitDesktop: React.FC<{ + version: string, + defaultConfig: RqbitDesktopConfig, +}> = ({ version, defaultConfig }) => { + let [configured, setConfigured] = useState(false); + let [config, setConfig] = useState(defaultConfig); + let [configurationOpened, setConfigurationOpened] = useState(false); + + return <> + {configured && } + {configured && { + e.stopPropagation(); + setConfigurationOpened(true); + }} + href="#" + aria-label="Settings" />} + { + setConfigured(false); + }} + handleCancel={() => { + setConfigurationOpened(false); + }} + handleConfigured={(config) => { + setConfig(config); + setConfigured(true); + }} + initialConfig={config} /> + +} \ No newline at end of file