2021-05-02 12:29:43 +00:00
|
|
|
import { RouteComponentProps } from '@reach/router';
|
|
|
|
import React from 'react';
|
2021-09-17 09:55:15 +00:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2021-05-02 12:29:43 +00:00
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
import { useModule } from '../../lib/react-utils';
|
|
|
|
import apiReducer, { modules } from '../../store/api/reducer';
|
|
|
|
|
|
|
|
export default function HTTPPage(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
params: RouteComponentProps<unknown>,
|
|
|
|
): React.ReactElement {
|
2021-09-17 09:55:15 +00:00
|
|
|
const { t } = useTranslation();
|
2021-05-02 12:29:43 +00:00
|
|
|
const [moduleConfig, setModuleConfig] = useModule(modules.moduleConfig);
|
|
|
|
const [httpConfig, setHTTPConfig] = useModule(modules.httpConfig);
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
const busy = moduleConfig === null || httpConfig === null;
|
|
|
|
const active = moduleConfig?.static ?? false;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2021-09-17 09:55:15 +00:00
|
|
|
<h1 className="title is-4">{t('http.header')}</h1>
|
2021-05-02 12:29:43 +00:00
|
|
|
<div className="field">
|
2021-09-17 09:55:15 +00:00
|
|
|
<label className="label">{t('http.server-port')}</label>
|
2021-05-02 12:29:43 +00:00
|
|
|
<p className="control">
|
|
|
|
<input
|
|
|
|
disabled={busy}
|
|
|
|
className="input"
|
|
|
|
type="text"
|
2021-09-17 09:55:15 +00:00
|
|
|
placeholder=":8080"
|
2021-05-02 12:29:43 +00:00
|
|
|
value={httpConfig?.bind ?? ''}
|
|
|
|
onChange={(ev) =>
|
|
|
|
dispatch(
|
|
|
|
apiReducer.actions.httpConfigChanged({
|
|
|
|
...httpConfig,
|
|
|
|
bind: ev.target.value,
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</p>
|
2021-09-17 09:55:15 +00:00
|
|
|
<p className="help">{t('http.server-port-note')}</p>
|
2021-05-02 12:29:43 +00:00
|
|
|
</div>
|
2021-09-17 09:55:15 +00:00
|
|
|
<label className="label">{t('http.static-content')}</label>
|
2021-05-02 12:29:43 +00:00
|
|
|
<div className="field">
|
|
|
|
<label className="checkbox">
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
disabled={busy}
|
|
|
|
checked={active}
|
|
|
|
onChange={(ev) =>
|
|
|
|
dispatch(
|
|
|
|
apiReducer.actions.moduleConfigChanged({
|
|
|
|
...moduleConfig,
|
|
|
|
static: ev.target.checked,
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>{' '}
|
2021-09-17 09:55:15 +00:00
|
|
|
{t('http.enable-static')}
|
2021-05-02 12:29:43 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div className="field">
|
2021-09-17 09:55:15 +00:00
|
|
|
<label className="label">{t('http.static-root-path')}</label>
|
2021-05-02 12:29:43 +00:00
|
|
|
<p className="control">
|
|
|
|
<input
|
|
|
|
className="input"
|
|
|
|
type="text"
|
|
|
|
disabled={busy || !active}
|
|
|
|
value={httpConfig?.path ?? ''}
|
|
|
|
onChange={(ev) =>
|
|
|
|
dispatch(
|
|
|
|
apiReducer.actions.httpConfigChanged({
|
|
|
|
...httpConfig,
|
|
|
|
path: ev.target.value,
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<button
|
|
|
|
className="button"
|
|
|
|
onClick={() => {
|
|
|
|
dispatch(setModuleConfig(moduleConfig));
|
|
|
|
dispatch(setHTTPConfig(httpConfig));
|
|
|
|
}}
|
|
|
|
>
|
2021-09-17 09:55:15 +00:00
|
|
|
{t('actions.save')}
|
2021-05-02 12:29:43 +00:00
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|