-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from jreyesr/feat/default-delay
Add configuration option for default delay
- Loading branch information
Showing
7 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { useCallback, useEffect, useState } from 'react'; | ||
|
||
import ActionButton from './ActionButton'; | ||
import DelaySelector from './DelaySelector'; | ||
import FormRow from './FormRow'; | ||
|
||
import { readSettings, writeSettings } from '../utils'; | ||
|
||
export default function BatchDialogSettings({context}) { | ||
const [isDirty, setIsDirty] = useState(false); | ||
const setDirty = () => setIsDirty(true); | ||
|
||
const [defaultDelay, setDefaultDelay] = useState(0); | ||
// When mounting component, read from storage to init state | ||
useEffect(() => { | ||
async function loadSettings() { | ||
const settings = await readSettings(context.store); | ||
setDefaultDelay(parseFloat(settings.defaultDelay ?? 0)); | ||
} | ||
loadSettings(); | ||
}, []) | ||
|
||
const saveSettings = useCallback(async () => { | ||
await writeSettings(context.store, { | ||
defaultDelay: defaultDelay, | ||
}); | ||
context.app.alert("Success!", "Settings saved") | ||
setIsDirty(false); | ||
|
||
// Refetch data from store, to ensure that it was saved | ||
const settings = await readSettings(context.store); | ||
setDefaultDelay(parseFloat(settings.defaultDelay)); | ||
}, [defaultDelay]); | ||
|
||
const onChangeDelay = ({target: {value}}) => { | ||
if(value < 0) return; | ||
setDefaultDelay(parseFloat(value)); | ||
setDirty(); | ||
} | ||
|
||
return (<React.Fragment> | ||
<FormRow label="Default delay"> | ||
<DelaySelector value={defaultDelay} onChange={onChangeDelay}/> | ||
</FormRow> | ||
|
||
<ActionButton title="Save" icon="fa-save" onClick={saveSettings} disabled={!isDirty}/> | ||
</React.Fragment>); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters