dispatch/client/js/components/pages/Settings.js

88 lines
2.4 KiB
JavaScript
Raw Normal View History

import React, { useCallback } from 'react';
2020-04-30 12:36:30 +00:00
import Navicon from 'components/ui/Navicon';
import Button from 'components/ui/Button';
2018-10-15 06:56:17 +00:00
import Checkbox from 'components/ui/Checkbox';
import FileInput from 'components/ui/FileInput';
2018-10-15 06:56:17 +00:00
const Settings = ({
settings,
installable,
2018-11-22 11:00:18 +00:00
version,
2018-10-15 06:56:17 +00:00
setSetting,
onCertChange,
onKeyChange,
onInstall,
2018-10-15 06:56:17 +00:00
uploadCert
}) => {
2018-04-25 03:36:27 +00:00
const status = settings.uploadingCert ? 'Uploading...' : 'Upload';
const error = settings.certError;
2019-01-30 02:51:13 +00:00
const handleInstallClick = useCallback(async () => {
installable.prompt();
await installable.userChoice;
onInstall();
}, [installable]);
return (
2018-10-15 06:56:17 +00:00
<div className="settings-container">
<div className="settings">
<Navicon />
<h1>Settings</h1>
{installable && (
2020-04-30 12:36:30 +00:00
<Button
className="settings-button button-install"
onClick={handleInstallClick}
>
<h2>Install</h2>
</Button>
)}
2018-10-15 06:56:17 +00:00
<div className="settings-section">
<h2>Visuals</h2>
<Checkbox
name="coloredNicks"
label="Colored nicks"
2020-06-24 23:50:10 +00:00
checked={!!settings.coloredNicks}
2018-10-15 06:56:17 +00:00
onChange={e => setSetting('coloredNicks', e.target.checked)}
/>
</div>
<div className="settings-section">
<h2>Client Certificate</h2>
<div className="settings-cert">
<div className="settings-file">
<p>Certificate</p>
<FileInput
name={settings.certFile || 'Select Certificate'}
onChange={onCertChange}
/>
</div>
<div className="settings-file">
<p>Private Key</p>
<FileInput
name={settings.keyFile || 'Select Key'}
onChange={onKeyChange}
/>
</div>
<Button
type="submit"
className="settings-button"
onClick={uploadCert}
>
2018-10-15 06:56:17 +00:00
{status}
</Button>
2018-10-15 06:56:17 +00:00
{error ? <p className="error">{error}</p> : null}
</div>
</div>
2018-11-22 11:00:18 +00:00
{version && (
<div className="settings-version">
<p>{version.tag}</p>
<p>Commit: {version.commit}</p>
<p>Build Date: {version.date}</p>
</div>
)}
</div>
</div>
);
};
export default Settings;