import { WebApplication } from '@/ui_models/application'; import { AppState } from '@/ui_models/app_state'; import { isDev } from '@/utils'; import { observer } from 'mobx-react-lite'; import { FunctionComponent } from 'preact'; import { useEffect, useState } from 'preact/hooks'; import { Checkbox } from '../Checkbox'; import { Icon } from '../Icon'; import { InputWithIcon } from '../InputWithIcon'; type Props = { application: WebApplication; appState: AppState; disabled?: boolean; }; export const AdvancedOptions: FunctionComponent = observer( ({ appState, application, disabled = false, children }) => { const { server, setServer, enableServerOption, setEnableServerOption } = appState.accountMenu; const [showAdvanced, setShowAdvanced] = useState(false); useEffect(() => { if (isDev && window._devAccountServer) { setEnableServerOption(true); setServer(window._devAccountServer); application.setCustomHost(window._devAccountServer); } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const handleServerOptionChange = (e: Event) => { if (e.target instanceof HTMLInputElement) { setEnableServerOption(e.target.checked); } }; const handleSyncServerChange = (e: Event) => { if (e.target instanceof HTMLInputElement) { setServer(e.target.value); application.setCustomHost(e.target.value); } }; const toggleShowAdvanced = () => { setShowAdvanced(!showAdvanced); }; return ( <> {showAdvanced ? (
{children}
) : null} ); } );