Skip to content

Commit

Permalink
add debounce in setting
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyLaw committed Apr 2, 2020
1 parent 024dba3 commit 98c2489
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { jsx } from '@emotion/core';
import { useState, useContext } from 'react';
import { JsonEditor } from '@bfc/code-editor';
import formatMessage from 'format-message';
import { DefaultButton } from 'office-ui-fabric-react/lib/Button';
import { ChoiceGroup } from 'office-ui-fabric-react/lib/ChoiceGroup';
import { Link } from 'office-ui-fabric-react/lib/Link';
import { Toggle } from 'office-ui-fabric-react/lib/Toggle';
import debounce from 'lodash/debounce';

import { StoreContext } from '../../../store';
import { isAbsHosted } from '../../../utils/envUtil';
Expand All @@ -34,13 +34,11 @@ export const DialogSettings = () => {
const { luis, MicrosoftAppPassword, MicrosoftAppId, ...settings } = origSettings;
const managedSettings = { luis, MicrosoftAppPassword, MicrosoftAppId };
const visibleSettings = absHosted ? settings : origSettings;
const [value, setValue] = useState(visibleSettings);
const [editing, setEditing] = useState(false);
const [slot, setSlot] = useState(botEnvironment === 'editing' ? 'integration' : botEnvironment);

const changeEditing = (_, on) => {
setEditing(on);
console.log(on);
actions.setEditDialogSettings(projectId, on, absHosted ? slot : undefined);
};

Expand All @@ -64,13 +62,11 @@ export const DialogSettings = () => {
}
};

const handleChange = (result, commit) => {
setValue(result);
console.log('on change');
if (commit && editing) {
const handleChange = debounce(result => {
if (editing) {
saveChangeResult(result);
}
};
}, 200);

const hostedControl = () => (
<div css={hostedControls}>
Expand All @@ -96,9 +92,6 @@ export const DialogSettings = () => {
const toggle = () => (
<div css={hostedToggle}>
<Toggle label={hostControlLabels.showKeys} inlineLabel onChange={changeEditing} defaultChecked={editing} />
{/* {absHosted && (
<DefaultButton disabled={!editing} text={formatMessage('Save')} onClick={() => handleChange(value, true)} />
)} */}
</div>
);

Expand All @@ -108,7 +101,7 @@ export const DialogSettings = () => {
{toggle()}
<div css={settingsEditor}>
<JsonEditor
onChange={x => handleChange(x, true)}
onChange={x => handleChange(x)}
options={{ readOnly: !editing }}
value={visibleSettings}
obfuscate={!editing}
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/lib/code-editor/src/BaseEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const BaseEditor: React.FC<BaseEditorProps> = props => {
const [hovered, setHovered] = useState(false);
const [focused, setFocused] = useState(false);
const [editor, setEditor] = useState<any>();
const initialValue = useMemo(() => value || (hidePlaceholder ? '' : placeholder), []);
const initialValue = useMemo(() => value || (hidePlaceholder ? '' : placeholder), [value]);

const onEditorMount: EditorDidMount = (getValue, editor) => {
setEditor(editor);
Expand Down

0 comments on commit 98c2489

Please sign in to comment.