2023-12-06 22:38:55 +00:00
|
|
|
import { useState } from "react";
|
2023-12-11 19:58:53 +00:00
|
|
|
import { RqbitWebUI } from "rqbit-webui/src/rqbit-web";
|
2023-12-07 00:13:11 +00:00
|
|
|
import { CurrentDesktopState, RqbitDesktopConfig } from "./configuration";
|
2023-12-06 22:38:55 +00:00
|
|
|
import { ConfigModal } from "./configure";
|
2023-12-14 10:37:29 +00:00
|
|
|
import { IconButton } from "rqbit-webui/src/components/buttons/IconButton";
|
2023-12-11 19:58:53 +00:00
|
|
|
import { BsSliders2 } from "react-icons/bs";
|
|
|
|
|
import { APIContext } from "rqbit-webui/src/context";
|
2023-12-08 19:47:48 +00:00
|
|
|
import { makeAPI } from "./api";
|
2023-12-06 22:38:55 +00:00
|
|
|
|
|
|
|
|
export const RqbitDesktop: React.FC<{
|
2023-12-07 14:11:12 +00:00
|
|
|
version: string;
|
|
|
|
|
defaultConfig: RqbitDesktopConfig;
|
|
|
|
|
currentState: CurrentDesktopState;
|
2023-12-07 00:13:11 +00:00
|
|
|
}> = ({ version, defaultConfig, currentState }) => {
|
2023-12-07 14:11:12 +00:00
|
|
|
let [configured, setConfigured] = useState<boolean>(currentState.configured);
|
|
|
|
|
let [config, setConfig] = useState<RqbitDesktopConfig>(
|
|
|
|
|
currentState.config ?? defaultConfig
|
|
|
|
|
);
|
|
|
|
|
let [configurationOpened, setConfigurationOpened] = useState<boolean>(false);
|
2023-12-09 00:26:14 +00:00
|
|
|
|
|
|
|
|
const configButton = (
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setConfigurationOpened(true);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<BsSliders2 />
|
|
|
|
|
</IconButton>
|
|
|
|
|
);
|
2023-12-06 22:38:55 +00:00
|
|
|
|
2023-12-07 14:11:12 +00:00
|
|
|
return (
|
2023-12-08 19:47:48 +00:00
|
|
|
<APIContext.Provider value={makeAPI(config)}>
|
2023-12-07 14:11:12 +00:00
|
|
|
{configured && (
|
2023-12-09 00:26:14 +00:00
|
|
|
<RqbitWebUI
|
2023-12-14 10:37:29 +00:00
|
|
|
title={`Rqbit Desktop - v${version}`}
|
2023-12-09 00:26:14 +00:00
|
|
|
menuButtons={[configButton]}
|
|
|
|
|
></RqbitWebUI>
|
2023-12-07 14:11:12 +00:00
|
|
|
)}
|
|
|
|
|
<ConfigModal
|
|
|
|
|
show={!configured || configurationOpened}
|
|
|
|
|
handleStartReconfigure={() => {
|
|
|
|
|
setConfigured(false);
|
|
|
|
|
}}
|
|
|
|
|
handleCancel={() => {
|
|
|
|
|
setConfigurationOpened(false);
|
|
|
|
|
}}
|
|
|
|
|
handleConfigured={(config) => {
|
|
|
|
|
setConfig(config);
|
|
|
|
|
setConfigurationOpened(false);
|
|
|
|
|
setConfigured(true);
|
|
|
|
|
}}
|
|
|
|
|
initialConfig={config}
|
|
|
|
|
defaultConfig={defaultConfig}
|
|
|
|
|
/>
|
2023-12-08 19:47:48 +00:00
|
|
|
</APIContext.Provider>
|
2023-12-07 14:11:12 +00:00
|
|
|
);
|
|
|
|
|
};
|