mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-19 22:46:20 -05:00
Showing loader when saving settings. Adding HelpPopup when hotspot and power-save are disabled.
This commit is contained in:
parent
c681c500e8
commit
25e638ed10
2 changed files with 62 additions and 42 deletions
|
|
@ -3,7 +3,7 @@ import {
|
|||
Button,
|
||||
Checkbox,
|
||||
Confirm,
|
||||
Container,
|
||||
Container, Dimmer,
|
||||
Divider,
|
||||
Form,
|
||||
Header,
|
||||
|
|
@ -44,6 +44,7 @@ class Settings extends React.Component {
|
|||
this.state = {
|
||||
disabled: false,
|
||||
hotspot_encryption: 'WPA',
|
||||
pending: false,
|
||||
qrCodeValue: '',
|
||||
qrOpen: false,
|
||||
ready: false,
|
||||
|
|
@ -84,6 +85,7 @@ class Settings extends React.Component {
|
|||
|
||||
async handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
this.setState({disabled: true, pending: true});
|
||||
let settings = {
|
||||
download_on_startup: this.state.download_on_startup,
|
||||
hotspot_on_startup: this.state.hotspot_on_startup,
|
||||
|
|
@ -93,6 +95,7 @@ class Settings extends React.Component {
|
|||
timezone: this.state.timezone.value,
|
||||
}
|
||||
await saveSettings(settings);
|
||||
this.setState({disabled: false, pending: false});
|
||||
}
|
||||
|
||||
handleInputChange = async (e, name, value) => {
|
||||
|
|
@ -120,6 +123,7 @@ class Settings extends React.Component {
|
|||
hotspot_on_startup,
|
||||
hotspot_password,
|
||||
hotspot_ssid,
|
||||
pending,
|
||||
qrCodeValue,
|
||||
throttle_on_startup,
|
||||
timezone,
|
||||
|
|
@ -211,6 +215,10 @@ class Settings extends React.Component {
|
|||
Save
|
||||
</Button>
|
||||
|
||||
<Dimmer active={pending} inverted>
|
||||
<Loader active={pending} size='large'/>
|
||||
</Dimmer>
|
||||
|
||||
</Form>
|
||||
</Container>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -662,47 +662,6 @@ export function CardGroupCentered(props) {
|
|||
)
|
||||
}
|
||||
|
||||
export function HotspotToggle(props) {
|
||||
let {on, setHotspot} = useHotspot();
|
||||
return <Checkbox toggle {...props}
|
||||
label='WiFi Hotspot'
|
||||
disabled={on === null}
|
||||
checked={on === true}
|
||||
onChange={(e, data) => setHotspot(data.checked)}
|
||||
/>;
|
||||
}
|
||||
|
||||
export function ThrottleToggle(props) {
|
||||
let {on, setThrottle} = useThrottle();
|
||||
return <Checkbox toggle {...props}
|
||||
label='CPU Power-save'
|
||||
disabled={on === null}
|
||||
checked={on === true}
|
||||
onChange={(e, data) => setThrottle(data.checked)}
|
||||
/>;
|
||||
}
|
||||
|
||||
export function DisableDownloadsToggle() {
|
||||
let {on, setDownloads} = useDownloaders();
|
||||
return <Checkbox toggle
|
||||
label={on ? 'Downloading Enabled' : 'Downloading Disabled'}
|
||||
disabled={on === null}
|
||||
checked={on === true}
|
||||
onChange={(e, data) => setDownloads(data.checked)}
|
||||
/>;
|
||||
}
|
||||
|
||||
export function emptyToNull(obj) {
|
||||
const keys = Object.keys(obj);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const key = keys[i];
|
||||
if (obj[key] === '') {
|
||||
obj[key] = null;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
export function HelpPopup({icon, size, content, position}) {
|
||||
return <Popup
|
||||
content={content}
|
||||
|
|
@ -726,6 +685,59 @@ export function HelpHeader({icon, headerSize, iconSize, headerContent, popupCont
|
|||
)
|
||||
}
|
||||
|
||||
export function HotspotToggle(props) {
|
||||
let {on, setHotspot} = useHotspot();
|
||||
const disabled = on === null;
|
||||
return (
|
||||
<>
|
||||
<Checkbox toggle {...props}
|
||||
label='WiFi Hotspot'
|
||||
disabled={disabled}
|
||||
checked={on === true}
|
||||
onChange={(e, data) => setHotspot(data.checked)}
|
||||
/>
|
||||
{disabled && <HelpPopup content='Hotspot is not supported on this server'/>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function ThrottleToggle(props) {
|
||||
let {on, setThrottle} = useThrottle();
|
||||
const disabled = on === null;
|
||||
return (
|
||||
<>
|
||||
<Checkbox toggle {...props}
|
||||
label='CPU Power-save'
|
||||
disabled={disabled}
|
||||
checked={on === true}
|
||||
onChange={(e, data) => setThrottle(data.checked)}
|
||||
/>
|
||||
{disabled && <HelpPopup content='CPU Power-save is not supported on this server'/>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function DisableDownloadsToggle() {
|
||||
let {on, setDownloads} = useDownloaders();
|
||||
return <Checkbox toggle
|
||||
label={on ? 'Downloading Enabled' : 'Downloading Disabled'}
|
||||
disabled={on === null}
|
||||
checked={on === true}
|
||||
onChange={(e, data) => setDownloads(data.checked)}
|
||||
/>;
|
||||
}
|
||||
|
||||
export function emptyToNull(obj) {
|
||||
const keys = Object.keys(obj);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const key = keys[i];
|
||||
if (obj[key] === '') {
|
||||
obj[key] = null;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
export function minutesToTimestamp(minutes) {
|
||||
minutes = Math.round(minutes);
|
||||
const hours = String(Math.floor(minutes / 60)).padStart(1, '0');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue